JS judge name ID card mobile phone number Regular Expression

Source: Internet
Author: User

Function checkform1 ()
{

If (form1.username. value = "")
{
Alert ("name cannot be blank! ");
Return false;
}
If (! Iscardname (form1.username. Value ))
{
Alert ("name error! ");
Return false;
}
If (form1.usercode. value = "")
{
Alert ("ID card number cannot be blank! ");
Return false;
}
If (! Isidcard (form1.usercode. Value ))
{
Alert ("Incorrect ID card number! ");
Return false;
}
If (form1.msisdn. value = "")
{
Alert ("the mobile phone number cannot be blank! ");
Return false;
}



If (! Ismobile (form1.msisdn. Value ))
{
Alert ("mobile phone number error! ");
Return false;
}
VaR promit = Document. getelementbyid ("fillinfoform_promit ");
If (promit. Checked! = True ){
Alert ("You have not yet agreed to the terms of service ");
Return false;
}
Return true;
}
// Check Chinese Characters
Function ischinese (s)
{
VaR patrn =/^ \ s * [\ u4e00-\ u9fa5] {1, 15} \ s * $ /;
If (! Patrn.exe C (s ))
{
Return false;
}
Return true;
}

// Number
Function isnumber (s)
{
VaR patrn =/^ \ s * \ D + \ s * $ /;
// Var patrn1 =/^ \ s * \ D {16} [\ dxx] {2} \ s * $ /;
If (! Patrn.exe C (s ))
{
Return false;
}
Return true;
}
// Verify the mobile phone number: it must start with a number
Function ismobile (s)
{
VaR patrn =/^ \ s * (15 \ D {9} | 13 [0-9] \ D {8}) \ s * $ /;
If (! Patrn.exe C (s ))
{
Return false;
}
Return true;
}

// Check your ID card
Function isidcard (s)
{
VaR patrn =/^ \ s * \ D {15} \ s * $ /;
VaR patrn1 =/^ \ s * \ D {16} [\ dxx] {2} \ s * $ /;
If (! Patrn.exe C (s )&&! Patrn1.exec (s ))
{
Return false;
}
Return true;
}

// Check name: The name is a string of 2 to 15 characters.
Function iscardname (s)
{
VaR patrn =/^ \ s * [\ u4e00-\ u9fa5] {1,} [\ u4e00-\ u9fa5. ·] {0, 15} [\ u4e00-\ u9fa5] {1,} \ s * $ /;

If (! Patrn.exe C (s ))
{
Return false;
}
Return true;
}

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.