e-mail validation JavaScript code for regular expressions

Source: Internet
Author: User
Tags top level domain

Fuchangxi's Regular:

Copy CodeThe code is as follows:
/^ ([0-9a-za-z\-_\.] +) @ ([0-9a-z]+\. [A-z] {2,3} (\. [A-z] {2})?) $/g


The start must be one or more word characters or--plus @, then one or more word characters or--. Then the point is "." and a combination of word characters and--can have one or more combinations.

Copy CodeThe code is as follows:
<script type= "Text/javascript" >
function Isemail (str) {
var reg =/^ ([a-za-z0-9_-]) [email protected] ([a-za-z0-9_-]) + (. [ A-za-z0-9_-]) +/;
return Reg.test (str);
}
var str = ' [email protected] ';
document.write (Isemail (str) + ' <br/> ');
var str2 = ' [email protected] ';
document.write (Isemail (str2) + ' <br/> ');
var str3 = ' [email protected] ';
document.write (Isemail (STR3) + ' <br/> ');
var str4 = ' [email protected] ';
document.write (Isemail (STR4) + ' <br/> ');
var str5 = ' [email protected] ';
document.write (Isemail (STR5) + ' <br/> ');
</script>


I don't quite understand the specific rules of the mailbox. It's easier to feel the regular.

Check out several types of mailbox @ prefixes

1, Pure Digital
For example: [email protected]
2, Pure Letter
3. Mixed alphanumeric numbers
4, with a point of
For example: [email protected]
5. Underlined
For example: [email protected]
6. With connecting Wire
For example: [email protected]
The mailbox domain has at least one "." And two words, then strictly point then the last top level domain to be at least 2 letters, Max? With the domain name "name" as the standard, then the largest is 4, relaxed point is set to 5 bar ^_^.

Of course the above impossible situation: with "_" or "-" beginning or end, containing the special symbol.
Therefore, the regular expression I gave is as follows:

/^ ([0-9a-za-z\-_\.] +) @ ([0-9a-z]+\. [A-z] {2,3} (\. [A-z] {2})?) $/g

Copy CodeThe code is as follows:


<script type= "Text/javascript" >
Fchkmail=function (Szmail) {
var szreg=/^ ([0-9a-za-z\-_\.] +) @ ([0-9a-z]+\. [A-z] {2,3} (\. [A-z] {2})?) $/g;
var bchk=szreg.test (Szmail);
return bchk;
}
</script>
<input type= "text" id= "Mail" value= ""/>
<input type= "button" value= "Verify the Mailbox Address" onclick= "alert (Fchkmail (document.getElementById (' Mail '). Value));"/>
<p> email cannot start and end with-_. and other special characters </p>
<p> the end of the mailbox domain name is 2~5 letters, such as CN, COM, name</p>

Original connection:

JavaScript Regular expression Verification e-mail address

Compare the regular expression of authentic verification mailbox JS code detailed

e-mail validation JavaScript code for regular expressions

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.