Description: A script that closely examines the content of a form box to ensure that the user entered a valid email address. If not, the form submition is canceled, and the surfer prompted to re-enter a valid address. If it is, the script continues and checks whether the address is of a certain type (such as hotmail and yahoo), and if it is, blocks the form submition as well. In essense, this script allows you to not only block invalid email addresses, but "casual" addresses as well. The script makes the following assumptions regarding what a valid email address is:

-Contains a least one character procedding the "@"
-Contains a "@" following the procedding character(s)
-Contains at least one character following the "@", followed by a dot (.), followed by either a two character or three character string (a two character country code or the standard three character US code, such as com, edu etc)

Note that this script requires NS 4.x or IE 4.x to function- all other browsers will simply not participate in the form validation process.

Example:
(Entering myaddress@something.com is ok, whereas bad@something and casual@hotmail.com are not)

Please input a valid email address:

Directions: Simply cut and paste the below code into the <body> section of your page. It
contains a form with one box that is checked for "email validity". You can add in more form elements into the form, as you would with any other form.

<form name="validation" onSubmit="return checkbae()"> Please input a valid email address:<br> <input type="text" size=18 name="emailcheck"> <input type="submit" value="Submit"> </form> <script language="JavaScript1.2"> /* Advanced Email Check credit- By Website Abstraction (www.wsabstract.com) Over 200+ free scripts here! */ var invalidaddress=new Array() invalidaddress[0]="hotmail" invalidaddress[1]="rocketmail" invalidaddress[2]="yahoo" invalidaddress[3]="zdnetmail" //extend or shorten this list if neccessary var testresults function checkemail(){ var invalidcheck=0; var str=document.validation.emailcheck.value var filter=/^.+@.+\..{2,3}$/ if (filter.test(str)){ var tempstring=str.split("@") tempstring=tempstring[1].split(".") for (i=0;i<invalidaddress.length;i++){ if (tempstring[0]==invalidaddress[i]) invalidcheck=1 } if (invalidcheck!=1) testresults=true else{ alert("Please input a more official email address!") testresults=false } } else{ alert("Please input a valid email address!") testresults=false } return (testresults) } </script> <script> function checkbae(){ if (document.layers||document.all) return checkemail() else return true } </script>

The type of addresses that are to be blocked are contained inside the array "invalidaddress". Change those to your own. Note that the message that will be alerted when a user enters one of these email addresses is "Please input a more official email address!" You may wish to change that message.

1998 Copyright (C) Next Step Publishing All Rights Reserved