First page Back Continue Last page Image

Build Your Test Vehicle

<html>

<head>

<title>The Validator</title>

<script language="javascript" type="text/javascript">

<!-- Hide script from older browsers

function validEmail(email) {

invalidChars = " /:,;"

if (email == "") {

return false

}

for (i=0; i<invalidChars.length; i++) {

badChar = invalidChars.charAt(i)

if (email.indexOf(badChar,0) != -1) {

return false

}

}

atPos = email.indexOf("@",1)

if (atPos == -1) {

return false

}

if (email.indexOf("@",atPos+1) != -1) {

return false

}

periodPos = email.indexOf(".",atPos)

if (periodPos == -1) {

return false

}

if (periodPos+3 > email.length) {

return false

}

return true

}

function submitIt(form) {

if (!validEmail(form.emailAddr.value)) {

alert("Invalid email address")

form.emailAddr.focus()

form.emailAddr.select()

return false

}

return true

}

// End hiding script -->

</script>

</head>

<body bgcolor="#f5fffa">

<center><font size="+3">Car Picker</font></center>

<form name="emailtest" method="post" action="mailto:sf_nicole@yahoo.com"

onSubmit="return submitIt(emailtest)">

<table border="0" cellspacing="8" cellpadding="8">

<tr>

<td colspan="5">

Your Email Address: <input name="emailAddr" type="text" size="30">

</td>

</tr>

<tr>

<td><p><input type="submit" value="Submit">

<input type="reset" value="Reset">

</td>

</tr>

</table>

</form>

</body>

</html>

function validEmail(email) {

var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

return re.test(email);

}

Replace the part in Red From one our earlier scripts with the part in green, It is not only shorter but it is more precise