Javascript Number Validation - Javascript

How to do number validation using javascript?

Snippet Code

Rate this page :
  [ 1 votes]

The following javascript code can be used to allow only numbers inside the text box. Here, check() function is used for number validation.

<script type="text/javascript"> function check(txtval){ var num = txtval.value; if(isNaN(num)) { num = num.substring(0,(num.length-1)); txtval.value = num; } } </script> Enter Number: <input type="text" onkeyup="check(this)" />


Ask Questions

Ask Question