More authentic verification of the mailbox regular expression JS code detailed _ Regular expression

Source: Internet
Author: User
the regular of the Fuchangxi:
Copy Code code as follows:

/^ ([a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + (. [ A-za-z0-9_-]) +/

The beginning must be one or more word characters or--, plus @, then one or more word characters or--. And then the dot "." and a combination of word characters and-can have one or more combinations.
Copy Code code 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 don't know the exact rules of the mailbox. It's easier to feel this way.

count the types of mailbox @ prefixes

1, Pure Digital
For example: 123456@jb51.net
2, Pure Letter
3. Alphanumeric mixing
4, with a dot of
For example: web.blue@jb51.net
5, underlined
For example: web_blue@jb51.net
6, with connecting wiring
For example: web-blue@jb51.net
The mailbox field has at least one "." and two words, and then the last top-level domain should be at least 2 letters, Max? The domain name "name" as the subject, then the biggest is 4, loose point set to 5 bar ^_^.

Of course the above impossible situation: with "_" or "-" to the beginning or end, containing special symbols.
Therefore, the regular expressions I give are as follows:

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

Copy Code code 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 Mailbox Address "onclick=" alert (Fchkmail (document.getElementById (' Mail '). Value); "/>
<p> mailboxes cannot start and end with-_. and other special characters </p>
<p> mailbox domain names end with 2~5 letters, such as CN, COM, 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.