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 emailAdd=mailform.emailbox.value; if (mailform.emailbox.value==""||mailform.emailbox.value.indexOf('@',0)==-1)// to search for the character @ alert("Please enter a valid email address"); else location="mailto:"+ emailAdd;} </script> <form name="mailform" onsubmit="sendMail(this.form)"> email address:<input name="emailbox" type="text" value=""> <input type="submit" value="Send email"> </form>
Test it out here
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy