dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: JavaScript
Expertise: Intermediate
Jan 8, 2008

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Validate Email Addresses with a JavaScript Regular Expression

Often, email validation code for web applications checks only for the position of @ and period characters, also assuming the @ character will be in the front of period. But we all know the "a_b.c@gamil.com" is valid.

Did you know you can use a JavaScript Regular Expressions method to check email addresses? It is simple and efficient. Here's how:


<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Check Email Address</title>
<script language="javascript">
function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		alert("true");   
    }else{   
		alert("false"); 
    }
}
</script>
</head><body>
<form name="signupform">
Input your email: <input name="email" type="text" class="inputs" id="email_address"
 value="any@any.com" size="35" maxlength="255">
<input name="summit" type="submit" value="Check" onClick="checkEmail(document.signupform.email.value)">    
</form></body></html>
Gang Liu
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date