In JS to determine whether the variable is a digital isNaN function

Source: Internet
Author: User

isNaN function

isNaN (expression:object): Boolean

Common validation numbers

The code is as follows Copy Code

document.write (isNaN (123));//false
document.write (isNaN ( -1.23));//false
document.write (isNaN (5-2));//false
document.write (isNaN (0));//false
document.write (isNaN ("Hello"));//true
document.write (isNaN ("2005/12/12"));//true
document.write (isNaN ("6/2"));//true
document.write (isNaN ("3"));//false

Examples of applications

  code is as follows copy code


if ( isNaN (Document.login.imgcode.value)) {
   alert (' Captcha must be a number! ')
   document.login.imgcode.focus ();
   return false;
}

If (!isnum (document.getElementById ("Prjsum"). Value) {
    alert ("Cost can only be a number");
    document.getElementById ("Prjsum"). focus ();
    return false;
   
   }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.