PDA

View Full Version : Check if it`s string or number


marcelovcd
09-15-2002, 08:14 AM
Hello,

I`d like to know if there is a native function in javascript reference that check if it`s string or number. exemple.

12 -> It is a number
aaa -> it it a string

I am a computer science studant and I have to do a project . In this project , I need to know if the user typed a number or a string in some text filds.

thancks,

-TheDarkEye-
09-15-2002, 08:50 AM
function validateInt(iString) {
return (("" + parseInt(iString)) == iString);
}

that will validate an integer. floating point numbers require more complicated validation.

Delicates
09-15-2002, 06:37 PM
Originally posted by marcelovcd
Hello,

I`d like to know if there is a native function in javascript reference that check if it`s string or number. exemple.


isNaN (http://www.devguru.com/Technologies/ecmascript/quickref/isnan.html)()

Waves
09-19-2002, 07:30 PM
Cool function. I might include that in my forms to ensure that noone gives me numbers in their names...lol