Use String.indexOf method to validate an email address
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
function get_add(){
var email_add=window.prompt("What is your e-mail address?","");
if (email_add.indexOf("@") == -1) {
window.alert("No '@' symbol in your address");
}
if (email_add.indexOf(".") == -1){
window.alert("No '.' symbol in your address");
}
if ( (email_add.indexOf("@") != -1) && (email_add.indexOf(".") != -1) )
{
window.alert("Thanks!");
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT type="button" value="Click to enter an e-mail address" onClick="get_add();">
</BODY>
</HTML>
Related examples in the same category