Regular Expression learning notes, phone number, email, Chinese characters, numbers, and letters

Source: Internet
Author: User
Code

// VaR Reg =/^ (\ D +) | ([A-Z] +) $/g filters out one or more numbers from the beginning to the end, or one or more 26 letters
// VaR reg2 =/^ [\ u4e00-\ u9f5a] + $/g; filter out one or more Chinese characters from the beginning to the end.
// VaR reg3 =/^ \ D {1, 3} $/g; filter numbers ranging from 1 to 3
// VaR reg4 =/(^ \ s +) | (\ s + $)/g; select one or more spaces from the beginning to the end.
// Username. Replace (reg4, ""); replace the filtered space with null, that is, remove the space.
// VaR reg5 =/^ \ D {3, 4}-\ D {7, 8} $/g; select the phone number format from the beginning to the end, ranging from 123-1234567 to the longest 1234-12345678
// VaR reg6 =/(\ D +) | ([A-Z] +) @ (\ D +) | ([A-Z] + )). ([A-Z] {3 }$)/g; filter the email format of the copy.
 
Function Zhuce (){
VaR Username = Document. getelementbyid ( " Username " ). Value;
VaR Realname = Document. getelementbyid ( " Realname " ). Value;
VaR Age = Document. getelementbyid ( " Age " ). Value;
VaR Tel = Document. getelementbyid ( " Tel " ). Value;
VaR Email = Document. getelementbyid ( " Email " ). Value;

VaR Reg =   / ^ (\ D +) | ([A-Z] +) $ / G;
VaR Reg2 =   / ^ [\ U4e00-\ u9f5a] + $ / G;
VaR Reg3 =   / ^ \ D {1, 3} $ / G;
VaR Reg4 =   / (^ \ S +) | (\ s + $) / G;
VaR Reg5 =   / ^ \ D {3, 4}-\ D {7, 8} $ / G;
VaR Reg6 =   / (\ D +) | ([A-Z] +) @ (\ D +) | ([A-Z] + )). ([A-Z] {3} $) / G;

If (Username =   "" )
{
Alert ( " Login account cannot be blank " );
Document. getelementbyid ( " Username " ). Focus ();
Return ;
}

If ( ! Reg. Test (username ))
{
Alert (username +   " The Logon account can only contain numbers or letters. " );
Document. getelementbyid ( " Username " ). Focus ();
Return ;
}

If (Reg4.test (username ))
{
Alert (username +   " The login account contains spaces and is being removed automatically " );
Username = Username. Replace (reg4, "" );
Alert ( " Input " + Username + " . " );
Document. getelementbyid ( " Username " ). Select ();
Return ;
}

If ( ! Reg2.test (realname ))
{
Alert (realname +   " The real name must be in Chinese " );
Document. getelementbyid ( " Realname " ). Focus ();
Return ;
}

If ( ! Reg3.test (AGE ))
{
Alert (age +   " The age must be a number and cannot exceed 3 digits. " );
Document. getelementbyid ( " Age " ). Focus ();
Return ;
}

If ( ! Reg5.test (TEL ))
{
Alert (Tel +   " Incorrect Phone Number Format " );
Document. getelementbyid ( " Tel " ). Focus ();
Return ;
}

If ( ! Reg6.test (email ))
{
Alert (email +   " The email format is incorrect. " );
Document. getelementbyid ( " Email " ). Focus ();
Return ;
}
}

 

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.