How to validate a text box to type only numbers using jquery

Look the following text box and check it with the html code that use to create that text box .
eeee

<input id="textfield" type="text" name="textfiled" />

This is the function that use to validate .

 function isNumber(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    }

Then get your value of the text filed as below

 var inputValue = $('#textfield').val();

Now put this “inputValue” to above function as below .

if (isNumber(grade)) {
          //your code here...
        }

Leave a Comment