Client side validation for Number values

27 / May / 2010 by Vishal Sahu 2 comments

Hi,
Recently in my project , i needed to validate an input (whether it is a integer or not) on client side.
I tried many codes but they are bit lengthy. Then I encountered the simplest way as given below, which worked.
For any input value, it checks whether it is an Integer or not.

     function isInteger(a) {
      return (!(parseInt(a).toString() == 'NaN'))
        }

It worked for me ans saves a lot of time.
Hope it helps.

Regards
Vishal Sahu
vishal@intelligrape.com

FOUND THIS USEFUL? SHARE IT

comments (2)

  1. Amit Jain

    We also have isNaN() function defined in javascript which returns true if value passed is not a valid number.

    Thanks

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *