Common Regular Expressions in JavaScript (ID card number)

Source: Internet
Author: User
< Script Language = "JavaScript" >
Function Checkidcard (STR)
{
VaR Isidcard1 =   New Object ();
VaR Isidcard2 =   New Object ();

// ID card Regular Expression (15 digits)
Isidcard1 =/^ [ 1 - 9 ] \ D {7} (( 0 \ D) | ( 1 [ 0 - 2 ]) ([ 0 | 1 | 2 ] \ D) | 3 [ 0 - 1 ]) \ D {3} $ / ;

// ID card Regular Expression (18 digits)

Isidcard2 =/^ [ 1 - 9 ] \ D {5} [ 1 - 9 ] \ D {3} (( 0 \ D) | ( 1 [ 0 - 2 ]) ([ 0 | 1 | 2 ] \ D) | 3 [ 0 - 1 ]) (\ D {4}) | \ D {3} [A-Z]) $ / ;

// Verify your ID card. If it is correct, submit it to the reg. ASP page.
If (Isidcard1.test (STR) | Isidcard2.test (STR ))
{
Document. Forms [ " Form1 " ]. Action =   " ./Reg. asp " ;
Document. Forms [ 0 ]. Submit ();
Return   True ;
}
Alert ( " Enter the correct ID card! " );
Return   False ;

}
</ Script >
< Form Name = "Form1" Method = Post Onsubmit = "Return checkidcard (this. user_iden.value )" >
< Input Name = "User_iden" ID = "User_iden" Size = "18" >
< Input Type = "Submit" Name = "Testcall" Value = "Verify ID card number" >
</ Form >
Related Article

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.