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>


Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2023 All rights reserved worldwide Privacy Policy Disclaimer