Email validation in JavaScript

The below JavaScript code validates a textbox for correct email id. Whatever user enters if not a proper email id then it will display a message in the alert box.

<script type='text/javascript'>
function emailValidation()
var emailIdValue= /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
alert("Email Validation sucessfully");
return true;
alert("This email is invalid, give a proper email id");
return false;
Enter the E-mail Address value: <input type='text' id='txtEmail'/>
<input type='button' onclick="emailValidation()" id="btnSubmit" value='Submit' />

Leave a Reply

Your email address will not be published. Required fields are marked *