How to allow only numeric (0-9) in HTML inputbox using javascript?

HTML CODE


<input type="text" name="mobile"  onkeypress="return isNumber(event)" />

JAVASCRIPT CODE


function isNumber(evt) {
 evt = (evt) ? evt : window.event;
 var charCode = (evt.which) ? evt.which : evt.keyCode;
 if (charCode > 31 && (charCode < 48 || charCode > 57)) {
 return false;
 }
 return true;
}


DEMO 

Check this link http://jsfiddle.net/vetri/vsmju7xt/

Tagged as: