JavaScript Tutorial JavaScript Examples CSS Tutorial HTML Tutorial About Us

Email Validation

This JavaScript validate an email address before the user send it out. An email must have an @ character so the script will search for this character, if it is not found it will prompt the user to enter the email address again.

The Script is as follows:

<script language="javascript">

function sendMail(form){
var emailAdd
if (mailform.emailbox.value==""||mailform.emailbox.value.indexOf('@',0)==-1)// to search for the character @
alert("Please enter a valid email address");


location="mailto:"+ emailAdd;}
<form name="mailform" onsubmit="sendMail(this.form)">
email address:<input name="emailbox" type="text" value="">
<input type="submit" value="Send email">

Test it out here

email address:

Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy