79638837

Date: 2025-05-26 11:40:14
Score: 0.5
Natty:
Report link

I found here a solution with a onKeypress, that I adapt to use through a listener. What's the best way to automatically insert slashes '/' in date fields

You should find the way to adapt it adding the time.

For me, and only with date format work properly in those ways: you can add all in the input like this:

<input id="txtDate" name=x size=10 maxlength=10  onkeydown="this.value=this.value.replace(/^(\d\d)(\d)$/g,'$1/$2').replace(/^(\d\d\/\d\d)(\d+)$/g,'$1/$2').replace(/[^\d\/]/g,'')">

I'm using in this way with a listener:

function checkFecha() {
this.value = this.value.replace(/^(\d\d)(\d)$/g, '$1/$2').replace(/^(\d\d\/\d\d)(\d+)$/g, '$1/$2').replace(/[^\d\/]/g, '');}

txtDate.addEventListener('keydown', checkMyDate, false);

So in my case, the input don't contain the "onkeydown".

Regards!

Reasons:
  • Blacklisted phrase (1): Regards
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Patri Dev