×

Html & Html5

it training classes Logo

The World's best Software Development Study Portal

JavaScript Email Validation Example



Validating email is a very important point while validating an HTML form. In this page we have discussed how to validate an email using JavaScript :

There must be at least one character before and after the @.

<script>

function validateemail()

{

var x=document.myform.email.value;

var ata=x.indexOf("@");

var dotb=x.lastIndexOf(".");

if (ata<1 || dotb<ata+2 || dotb+2>=x.length){

alert("Please enter a valid e-mail address \n ata:"+ata+"\n dotb:"+dotb);

return false;

}

}

</script>

<form name="myform" method="post" action="#" onsubmit="return validateemail();">

Email: <input type="text" name="email"><br/>

<input type="submit" value="register">

</form>









JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute