.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Email Validation in Javascript

Posted By:John       Posted Date: April 06, 2009    Points: 10    Category: Javascript    URL: http://www.dotnetspark.com  
 


/* Defining the Regular expression */
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
/*Getting the value from the UI*/
var emailid=document.form1.Email.value;
/*Matching the UI value with Regular Expression*/
var matchArray = emailid.match(emailPat);
if (matchArray == null)
{
alert("Your email address seems incorrect. Please try again.");
document.form1.Email.focus();
return false;
}

     

Further Readings:

Responses
Author: Athira Sreejith         Company URL: http://www.dotnetspark.com
Posted Date: April 16, 2009

Hi..

You can try like this also.
<script>
function validateEmail(email)
{
var emailpat=/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
var matchArray=email.match(emailpat);
if(matchArray==null)
{
return false;
}
return true;
}

function validatectrl()
{
if(document.getElementById("txtemailid").value!="")
{
if(!validateEmail(document.getElementById("txtemailid").value))
{
alert("Invalid Email Address");
document.frmpostresume.txtemailid.focus();
return false;
}
}
}
</script>

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend