Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- isNaN(num) // returns true if the variable does NOT contain a valid number
- isNaN(123) // false
- isNaN('123') // false
- isNaN('foo') // true
- isNaN('10px') // true
- function isNumeric(num){
- return !isNaN(num)
- }
- +num // returns the numeric value of the string, or NaN if the
- // string isn't purely numeric characters
- +'12' // 12
- +'foo' // NaN
- +'12px' // NaN
- parseInt(num) // extracts a numeric value from the
- // start of the string, or NaN.
- parseInt('12') // 12
- parseInt('aaa') // NaN
- parseInt('12px') // 12
- parseInt('foo2') // NaN These last two may be different
- parseInt('12a5') // 12 from what you expected to see.
- parseInt(12.345) // 12
- parseInt('12.345') // 12
- +'12.345' // 12.345
- +'' // 0
- isNaN('') // false
- parseInt('') // NaN
- var num = "987238";
- if(num.match(/^d+$/)){
- //valid integer
- }else if(num.match(/^d+.d+$/)){
- //valid float
- }else{
- //not valid number
- }
Add Comment
Please, Sign In to add comment