I have a text field that allows a user to enter their age. I am trying to do some client-side validation on this field with JavaScript. I have server-side validation already
You may use isInteger() method of Number object
isInteger()
Number
if ( (new Number(x)).isInteger() ) { // handle integer }
This method works properly if x is undefined or null. But it has poor browser support for now
x
undefined
null