JS verification ID card number get birth date based on ID card number

Source: Internet
Author: User

 

/*

JS itself does not have the trim () function to cancel the blank characters in the string

Custom function: replace blank characters with regular expressions

*/

Function trim (s) {return S. Replace (/^ \ s + | \ s + $/g ,"");};

// Verify the ID card number and obtain the Date of birth
Function getbirthdatbyidno (iidno ){
VaR tmpstr = "";
VaR iddate = "";
VaR tmpint = 0;
VaR strreturn = "";

Iidno = trim (iidno );

If (iidno. length! = 15) & (iidno. length! = 18 )){
Strreturn = "the number of digits of the entered ID card number is incorrect ";
Return strreturn;
}

If (iidno. Length = 15 ){
Tmpstr = iidno. substring (6, 12 );
Tmpstr = "19" + tmpstr;
Tmpstr = tmpstr. substring (0, 4) + "-" + tmpstr. substring (4, 6) + "-" + tmpstr. substring (6)

Return tmpstr;
}
Else {
Tmpstr = iidno. substring (6, 14 );
Tmpstr = tmpstr. substring (0, 4) + "-" + tmpstr. substring (4, 6) + "-" + tmpstr. substring (6)

Return tmpstr;
}
}

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.