javascript - Allow only numbers to be typed in a textbox - default to zero -
How can it be modified that if a user does not enter a number, the number 0 will be entered in the text field, Thank you in advance:
function isNumber (evt) {evt = (evt)? Evt: window.event; Var charCode = (evt.which)? Evt.which: evt.keyCode; If (charcod> 31 and & quot; charcoda & lt; 48; charcode & gt; 57)} {return false; } Back true; }
If a user does not enter a number, then the text will be entered in the 0 Field
& lt; Input type = "text" id = "numeric" value = "0" onclick = "this.value = '' onblur =" if (this.value == '') {This.value = '0'} "/ & Gt; Regex for numbers only.
$ ('# numeric'). ('Input', function (event) {this.value = this .value.replace (/ [^ 0- 9] / g, '');});
Comments
Post a Comment