Email validation in JavaScript

We will develop a simple script to check user input in a text box. The input data should be one email address. So it must have two minimum chars present. One is @ and other one is presence of . ( dot ). To ensure this, we will use indexOf function. If both are present then the function will return true so the form will be submitted otherwise it will return false.

Demo of email validation

Source code is here

<body >
<script type="text/javascript" >
function check_form(){
var em=document.getElementById('em').value;
if(em.indexOf("@") < 1 || em.indexOf(".") < 1 )
alert('Please check your email address');
return false;
alert('Email validation passed, you will be taken to tutorial page');
return true;

<form method=post action='email-validation.php' onsubmit='return check_form()'; name='myForm'>
<input type=text name=em id='em'><input type=submit value=Submit>


Your Rating

More on List Box & JavaScript

Post Comment This is for short comments only. Use the forum for more discussions.

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 All rights reserved worldwide Privacy Policy Disclaimer