I can input
0 but not 0123. How do I prevent users not to input 0 at the first position of the input text field?
Let them input it, just trim it when focus changes:
inputElement.onblur = function() {
this.value = this.value.replace(/^0+(?=\d)/,'');
}
Note that it's specifically looking for a digit (\d
) after the 0's that it's nuking, so it won't touch the zero in something like 0.123
. If you want to get rid of those, too, just change the \d
to .
, which matches any character whatsoever.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments