Share on Google+Share on Google+

JavaScript Email Validation

This page discusses - JavaScript Email Validation

JavaScript Email Validation


In this section we are going to check email Validation using JavaScript.

JavaScript allows to perform a client side validation of email Ids in several forms. For this purpose, we have created an example which shows how you can validate an email address for a form. The function checkEmail() checks if the entered email id has the general syntax of an email. When user submits the email address then it calls the ValidateEmail() function which validates the email entered by the user in the text box.

Here is the code:

<h2>Email Validation</h2>
<script language = "Javascript">
function checkEmail() {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test({
document.write("You have entered valid email.");
return true;
return false; 
function ValidateEmail(){

if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
return false
if (checkEmail(emailID.value)==false){
alert("Invalid Email Adderess");
return false
return true
<form name="form" method="post" onSubmit="return ValidateEmail()">
Enter an Email Address : <input type="text" name="email" size="30"><br>
<input type="submit" name="Submit" value="Submit">

Output will be displayed as:

When user enters the invalid email, an alert box is displayed showing error message:

Download Source Code:





Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JavaScript Email Validation  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
December 6, 2011
email vailidation failed - Société

when i was testing for this above email, it failed. can anybody please help?
April 29, 2013
long & dificult code

sir the code for regestration form validation in java is very long and daificult. please sir create a short code for this.