first script:
// Validate Email 

var testresults

function checkemail(){
 var str=document.validation.emailcheck.value
 var filter=/^.+@.+\..{2,3}$/

 if (filter.test(str))
    testresults=true
 else {
    alert("Please input a valid email address!")
    testresults=false
}

copy the following code into the body of your html page:

<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>

second script:
function emailvalidation(entered, alertbox)
{
// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
} 
To force the browser to check each field immediately, we add an onChange to each of the <input> tags in the form.

For example: if we wanted to check if the value of a certain text field had a valid e-mail address we would add this:

<input type="text" name="Email" size="20" onChange="emailvalidation(this,'The E-mail is not valid');"> 
 
 

