Friday, 19 October 2012

JavaScript Email validation Using Regular Expression | PHP Tutorials for Beginners


JavaScript email Validation :

It is the simple code to help you in creating a form with email validation using regular expression.

<html>  
<head>  
<title>JavaScript form validation Using regular expression</title>   
<script type= "text/javascript">
function Validate(input)  
{  
var format = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
if(document.getElementById("email").value.match(format))  
{  
document.myform.email.focus();  
return true;  
}  
else  
{  
alert("You have entered an wrong email address!");  
document.myform.email.focus();  
return false;  
}  
}
</script>       
</head>  
<body>  
<h2>Input an email and Submit</h2>  
<form name="myform" action="#">   
<input type='text' name='email' id="email"/>
<input type="submit" name="submit" value="Submit"   onclick="Validate(document.myform.email)"/>
</form>  
</body>  
</html>

9 comments:

  1. i like this script very much thanks
    this is my email id:[email protected]
    please send me useful script such as above .thanks again.

    ReplyDelete
    Replies
    1. Thanks...You can follow our Facebook page Php Tutorials For Beginners, so you get updated whenever new content added to the blog.

      Delete
  2. thanks its work exactly

    ReplyDelete
  3. thank u, its working.....

    ReplyDelete
  4. Hi and tnx for sharing this code. But i have still problem to Check the length of the domain name.

    ReplyDelete