Detailed explanation of the js Code of the regular expression in the verified email address

Source: Internet
Author: User

Fuchangxi regular:
Copy codeThe Code is as follows:
/^ ([A-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + (. [a-zA-Z0-9 _-]) +/

It must start with one or more word characters or-, plus @, and then one or more word characters or -. Then there is a combination of "." And the word character and-. There can be one or more combinations.
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function isEmail (str ){
Var reg =/^ ([a-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + (. [a-zA-Z0-9 _-]) + /;
Return reg. test (str );
}
Var str = 'test @ hotmail.com ';
Document. write (isEmail (str) + '<br/> ');
Var str2 = 'test @ sima.vip.com ';
Document. write (isEmail (str2) + '<br/> ');
Var str3 = 'TE-st@qq.com.cn ';
Document. write (isEmail (str3) + '<br/> ');
Var str4 = 'te_st@sima.vip.com ';
Document. write (isEmail (str4) + '<br/> ');
Var str5 = 'TE .. _ st@sima.vip.com ';
Document. write (isEmail (str5) + '<br/> ');
</Script>

I am not familiar with the specific mailbox rules. It seems that this regular expression is relatively simple.

Count the mailbox @ prefix types

1. Pure numbers
For example: 123456@jb51.net
2. Pure letters
3. Mixed letters and numbers
4. vertex-based
For example: web.blue@jb51.net
5. Underline
For example: web_blue@jb51.net
6. Cable
For example: web-blue@jb51.net
The mailbox domain must have at least one "." And two words. Then, the last top-level domain must have at least two letters, the maximum? Take the domain name "name" as the standard. The maximum value is 4. Set the loose point to 5. ^_^.

Of course, the above is not possible: It starts or ends with "_" or "-" and contains special symbols.
Therefore, the regular expression I provide is as follows:

^ [A-Za-zd] + ([-_.] [A-Za-zd] +) * @ ([A-Za-zd] + [-.]) + [A-Za-zd] {2, 5} $

Copy codeThe Code is as follows:
<Script type = "text/javascript">
FChkMail = function (szMail ){
Var szReg =/^ [A-Za-zd] + ([-_.] [A-Za-zd] +) * @ ([A-Za-zd] + [-.]) + [A-Za-zd] {2, 5} $ /;
Var bChk = szReg. test (szMail );
Return bChk;
}
</Script>
<Input type = "text" id = "Mail" value = ""/>
<Input type = "button" value = "verify email address" onclick = "alert (fChkMail (document. getElementById ('mail'). value);"/>
<P> the email cannot start or end with-_. or other special characters </p>
<P> the email domain name ends with 2 ~ Five letters, such as cn, com, and name </p>

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.