JS phone, phone, e-mail address regular expression

Source: Internet
Author: User
Tags regular expression

We've collected this regular validation expression,
Email address
/^ ([a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + (. [ A-za-z0-9_-]) +/
Cell phone
/^0* (13|15) d{9}$/^0*


Match off any number of 0 of the opening.

Because the mobile phone number is 13 any number 9 bits, and 15 any number 9 bits, so can use (13|15) d{9} match

Phone

The number of the extension number is 3-4 digits, not required, but if filled with "-" and telephone number to connect

(-d{3,4})?

The regular of the Fuchangxi:


Select All
/^ ([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.

<script type= "text/web Effects" >
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>

Verify the mobile phone number, ignore the front 0, support 130-139,150-159. Ignore the front 0 and judge it to be 11-bit.

The regular of the Cloeft:

/^0* (13|15) d{9}$/^0*


Match off any number of 0 of the opening.

Because the mobile phone number is 13 any number 9 bits, and 15 any number 9 bits, so can use (13|15) d{9} match.

The test code is as follows:

<script language= "JavaScript" >
function Testreg (REG,STR) {
return Reg.test (str);
}
var reg =/^0* (13|15) d{9}$/;
var str = ' 13889294444 ';
var str2 = ' 12889293333 ';
var str3 = ' 23445567 ';
document.write (Testreg (reg,str) + ' <br/> ');
document.write (Testreg (REG,STR2) + ' <br/> ');
document.write (Testreg (REG,STR3) + ' <br/> ');
</script>

The area code must be filled with a 3-4-digit number, followed by "-" and the telephone number


^d{3,4}-

Number with 7-8 digits


d{7,8}


The number of the extension number is 3-4 digits, not required, but if filled with "-" and telephone number to connect

(-d{3,4})?


<script language= "javascript"

function Testreg (reg,str) {
  return reg.test (str);
 }
 var reg =/^d{3,4}-d{7,8} (-d{3,4})? $/;
 var str = ' 010-66880099 ';
 var str2 = ' 0533-7768990 ';
 document.write (Testreg (reg,str) + ' <br/> ');
 document.write (Testreg (REG,STR2) + ' <br/> ');
</script>
 

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.