开发者

how to check 01 02 number [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.
 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜