JS Regular Expression verification email format details _ javascript skills

Source: Internet
Author: User
This article mainly introduces the format of the JS Regular Expression verification mailbox. If you need some help, you can refer to it and hope to help us with WEB development. form verification is essential, so today we will list some common verification items, I hope you can criticize and correct the JS regular expression I just learned this afternoon.

I. Related code

The Code is as follows:


Function test ()
{
Var temp = document. getElementById ("text1 ");
// Email Verification
Var myreg =/^ ([a-zA-Z0-9] + [_ |/.]?) * [A-zA-Z0-9] + @ ([a-zA-Z0-9] + [_ |/.]?) * [A-zA-Z0-9] +/. [a-zA-Z] {2, 3} $ /;
If (! Myreg. test (temp. value ))
{
Alert ('prompt/n please enter a valid E_mail! ');
Myreg. focus ();
Return false;
}
}
// Because the methods are the same, write only the relevant Regular Expressions
// Verify the mobile phone number (two methods are provided)
Var mobile =/^ (13 [0-9] {1}) | 159 | 153) +/d {8} $ /;
Var mobile1 =/^ (13 +/d {9}) | (159 +/d {8}) | (153 +/d {8}) $ /;
// Area code verification
Var phoneAreaNum =/^/d {3, 4} $ /;
// Verify the phone number
Var phone =/^/d {7, 8} $ /;
}


Ii. Explanations
1./^ $/This is a common format.
^ Match the start position of the input string; $ match the end position of the input string

2. Enter the functions to be implemented.
* Matches the previous subexpression zero or multiple times;
+ Match the previous subexpression once or multiple times;
? Match the previous subexpression zero or one time;
/D matches a digit, which is equivalent to [0-9].
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.