How can i set onkeyup to output this format 00/00 instead 00/00/0000
JavaScript
x
8
1
<input type="text" onkeyup="
2
var v = this.value;
3
if (v.match(/^d{2}$/) !== null) {
4
this.value = v + '/';
5
} else if (v.match(/^d{2}/d{2}$/) !== null) {
6
this.value = v + '/';
7
}">
8
Advertisement
Answer
You could add maxlength="5"
JavaScript
1
7
1
<input type="text" maxlength="5" onkeyup="
2
var v = this.value;
3
this.value = v
4
.replace(/^(d{2})(?:/?)(d{1,2})$/, `$1/$2`)
5
.replace(/^(d{2})/$/, '$1');
6
">
7
I also improved your regex to use replace
and remove the /
automatically