how to check 01 02 number [closed]
var val= $('#num').val(); // 01
if(isNaN(val) || val > 59 || val== ''){
alert("error");
}
In this case, has not aler开发者_StackOverflow社区t error
var val= $('#num').val(); // 01
val = parseInt(val);
Well you code has no val in it, guessing it is a typo.
isNaN(val)
<-- checking to see if a string is a number?
val > 59
<-- comparing string vs a number. NOT a number vs Number
val== ''
<-- seeing if a string is matching nothing
You want to use parseInt() for the second check. Read the linked page.
You need to:
Define a variable name:
var yourVariable = "01";
Then use typeof to find its type:
typeof(yourVariable);
typeof
will return "string"
, in my example. It can also return "number"
or "undefined"
- very useful.
精彩评论