Ad Code

How to change date format to dd/mm/yyyy in html input

 <script>
function DDMMYYYY(value, event) {
  let newValue = value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1');

  const dayOrMonth = (index) => index % 2 === 1 && index < 4;

  // on delete key.  
  if (!event.data) { return value; }

  return newValue.split('').map((v, i) => dayOrMonth(i) ? v + '-' : v).join('');;
}
</script>

<input type="tel" maxlength="10" placeholder="dd-mm-yyyy" oninput="this.value = DDMMYYYY(this.value, event)" />



Post a Comment

0 Comments