Common JS Check

Source: Internet
Author: User

Id

function Iscardno (idcard) {///15-bit and 18-bit ID number of the regular expression var regidcard=/^ (^[1-9]\d{7} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3}$) | (^[1-9]\d{5}[1-9]\d{3} ((0\d) | (     1[0-2]) (([0|1|2]\d) |3[0-1]) ((\d{4}) |\d{3}[xx]) $) $/; If you pass this verification, the ID card format is correct, but the accuracy is also calculated if (Regidcard.test (Idcard)) {if (idcard.length==18) {var idcardwi=new Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); Save the first 17-bit weighting factor in the array var idcardy=new array (1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2); This is divided by 11, it is possible to generate 11-bit remainder, verification code, also save an array of Var idcardwisum=0; Used to store the sum of the first 17 bits and the weighted factor for the (Var i=0;i< -; i++) {idcardwisum+=idcard.substring (i,i+1) *idcardwi[i]; } var idcardmod=idcardwisum%11;//calculates the position of the array where the checksum is locatedvar idcardlast=idcard.substring (17);//Get last ID number//If equals 2, then the check code is 10, the last digit of the ID number should be x if (Idcardmod==2) {        if (Idcardlast= = "X" | | idcardlast== "X") {return true;        }else{return false; }}else{//Use the computed verification code to match the last identity card number, if it is consistent, the description passes, otherwise it is an invalid ID number if (idcardlast==idcardy[idcardmod]) {             return true;        }else{return false;     }}}}else{return false; }    }

Digital

function Isnumber (string,info) {     var number;    if (string==null) {        alert (info+ "can only enter numbers");        return false;     }    Number = new number (string);     if (IsNaN (number))     {         alert (info+ "can only enter numbers");        return false;     } else{        return true;    }}

Email

function Checkemail (email) {        var reemail =/^ ([a-za-z0-9]) (\w) [email protected] (\w) + (\.) (com|com\.cn|net|cn|net\.cn|org|biz|info|gov|gov\.cn|edu|edu\.cn)/;        if (!email.match (reemail) &&email! = "")        {                alert (' email format is incorrect! ');                return true;        }        else         {        return false;}        }

Empty

//----------------------------------------------------space to determine function iswhitespace (s) {     var whitespace = "\t\n \ r ";    var i;     < s . Length; i++)    {         = S.charat (i);          >= 0)         {        return true;        }    }        return false;}

Character

//--------------------------------------------------test character (limit characters that cannot be entered) function Ischar (s) {    var ErrorChar;    var Badchar = "><, []{}?/+=|\\ ' \":; [ Email protected]#$%^& () ' ";           " ")    {        alert ("Please enter your content!") ")        return false;    }        if (Iswhitespace (s))    {        alert ("characters entered cannot contain spaces, please re-enter!) ");         return false;    }    return true;}

Date

Date function Redate (s) {    s=s.split ("-");    S=s[0].replace ("\-", "") +s[1].replace ("\-", "") +s[2].replace ("\-", "");    return s;}

function Checkidno (sId) {    if (!/^\d{17} (\d|[ X]) $/i.test (sId) {          alert ("Please enter the correct ID number!");         return   false;       }       return true;}

Common JS Check

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.