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

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -