<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)" />
0 Comments