JS verification Email, telephone, cell phone number is regular

Source: Internet
Author: User

Verify the email core code as follows

The code is as follows Copy Code

function Isemail (input) {
var reg =/^w+ (-w+) | (. w+)) *@[a-za-z0-9]+ ((. | -) [a-za-z0-9]+] *. [a-za-z]+$/;
return reg.test (input);
}

Cases

<script type= "Text/javascript" defer= "defer" >

function Isemail (stremail)
{
if (/^w+ (-w+) | (stremail.search) | (. w+)) *@[a-za-z0-9]+ ((. | -) [a-za-z0-9]+] *. [a-za-z0-9]+$/)!=-1)
return true;
Else
Alert ("The email you entered is not valid, please re-enter!");
}

</script>
<body>
<form id= "Form1" runat= "Server" >
<div>

<asp:textbox id= "TextBox1" runat= "Server" onblur= Javascript:return isemail ($ (this). Val ()); ></asp:TextBox>
<asp:button id= "Button1" runat= "Server" text= "button" onclick= "Button1_Click"/>
</div>
</form>


Verify the phone number

The code is as follows Copy Code

function IsMobile (input) {
var reg=/^ (13[0-9]|15[0|3|6|7|8| 9]|18[8|9]) d{8}$/;
return reg.test (input);
}

Instance

The code is as follows Copy Code

<script type= "Text/javascript" >
function Checkmobile () {
var smobile = Document.mobileform.mobile.value
if (!) ( /^1[3|5][0-9]d{4,8}$/.test (Smobile))) {
Alert ("Not a full 11-digit cell phone number or the correct number of the top seven");
Document.mobileform.mobile.focus ();
return false;
}
}
</script>
<form action= "" Name= "Mobileform" method= "POST" onsubmit= "return Checkmobile ();" >
<input name= "mobile" class= "TDC" size= "a" maxlength= "one" >
<input name= ' action ' type= ' hidden ' value=mobile> <input ' class= bdtj ' name=b1 type=submit ' value= ' query >
</FORM>

Verifying phone number Codes

The code is as follows Copy Code

function Isphone (input) {
var reg=/^ ([0+]d{2,3}-)? ( 0d{2,3})-(d{7,8}) (-(D{3,})? $/;
return reg.test (input);
}

Example

The code is as follows Copy Code

function Checkphone (phone)    
{   
//Verify phone number, including 153,159 segment    
If (phone== "") {   
Alert ("Phone number cannot be empty!") ");    
return false;   
}   
if (phone!=" ") { & nbsp;  
var p1 =/^ ([0+]d{2,3}-)? ( 0d{2,3})? (d{7,8}) (-(D{3,})?$/;   
var me = false;   
if (p1.test (phone)) me=true;  & nbsp
if (!me) {      
//alert (' Sorry, www.111cn.net the phone number you entered has an error. Between area code and phone number please use-split ');     
return false;   
}   
}& nbsp; 
Return true;   
}  

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.