Matching email with js Regular Expressions

Source: Internet
Author: User

The regular expression matches the email address [\ w] + @ [\ w] +. [\ w] {2, 3} \ w to match any word characters including underlines. It is equivalent to \ '[A-Za-z0-9 _] \'. + Match the previous subexpression once or multiple times.

For example, 'Zo + 'can match "zo" and "zoo", but cannot match "z ". + Is equivalent to {1 ,}. Both {n, m} m and n are non-negative integers, where n <= m. Match at least n times and at most m times. For example, "o {1, 3}" matches the first three o in "fooooood. 'O {0, 1} 'is equivalent to 'o? '. Note that there must be no space between a comma and two numbers.


Example of a regular expression for Javascript mailbox Verification

The Code is as follows: Copy code


Myreg =/^ ([a-zA-Z0-9] + [_ |.]?) * [A-zA-Z0-9] + @ ([a-zA-Z0-9] + [_ |.]?) * [A-zA-Z0-9] +. [a-zA-Z] {2, 4} $/; Javascript

Email address verification Regular Expression example

The Code is as follows: Copy code


<Script type = "text/javascript">
Function isEmail (val ){
Var myreg =/^ ([a-zA-Z0-9] + [_ |.]?) * [A-zA-Z0-9] + @ ([a-zA-Z0-9] + [_ |.]?) * [A-zA-Z0-9] +. [a-zA-Z] {2, 4} $ /;
 
If (! Myreg. test (val ))
Return 'not mailbox ';
Return 'yesmail ';
};
Alert (isEmail ('I @ fufuok.com '));
</Script>

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.