Try this:
document.getElementById("<%= yourTextbox.ClientID %>").onkeyup = function() {
if (/^[0-9]{2}(.[0-9]{2})?$/.test(this.value)) {
this.value += ".";
}
}
What does this do? On
keyup
, it tests the value of the textbox against a regex that checks whether the textbox consists of 2 digits or of 2 digits + a dot + 2 digits. If it does, then it adds another dot.
Important note: if you want to use the textbox value on the server, then even with the above code, you should validate it at server-side. Even while the onkeyup function is there, that doesn't stop people from putting whatever they want in the textbox, hence you should always validate on server-side.