Forum Moderators: open
Put this script in the HEAD section:
<script language="JavaScript" type="text/javascript">
/*
Search for "document.yourform" and "document.yourform.email"
and replace with whatever matches the form on your page.
*/
<!--
function CheckEmail() {
document.yourform.email.value = document.yourform.email.value.toLowerCase();
var email = document.yourform.email.value;
var valid = "y";
if (email != "") {
if (email.length<7 ¦¦
email.indexOf("@.") != -1 ¦¦
email.indexOf("-.") != -1 ¦¦
email.indexOf("_.") != -1 ¦¦
email.indexOf("..") != -1 ¦¦
email.indexOf("._") != -1 ¦¦
email.indexOf(".-") != -1 ¦¦
email.indexOf(".@") != -1 ¦¦
email.indexOf("@-") != -1 ¦¦
email.indexOf("@_") != -1 ¦¦
email.indexOf("@") != email.lastIndexOf("@") ¦¦
email.indexOf("@") == -1 ¦¦
email.indexOf(".") == -1 ¦¦
(email.length - (email.lastIndexOf(".") + 1)) < 2) {
valid = "n";
alert("The e-mail address you entered is invalid.");
document.reg.mail.focus();
}
else {
a = "abcdefghijklmnopqrstuvwxyz0123456789@-_.";
b = 0;
while (b < email.length) {
if (a.indexOf(email.charAt(b)) == -1) {
valid = "n";
alert("The e-mail address may not contain \"" + email.charAt(b) + "\".");
document.yourform.email.focus();
b = email.length;
}
b = b + 1;
}
}
}
if (valid == "y") {
rx = /^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z][a-z]$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.aero$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.biz$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.coop$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.com$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.edu$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.gov$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.info$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.int$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.mil$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.museum$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.name$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.net$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.org$¦^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.pro$/i;
if (rx.test(email)) {
rx = /^[a-z0-9_]/i;
if(!(rx.test(email))) {
valid = "n";
alert("The e-mail address you entered is invalid.");
document.yourform.email.focus();
}
}
else {
valid = "n";
alert("The e-mail address you entered is invalid.");
document.yourform.email.focus();
}
}
if (valid == "y") {
document.yourform.submit();
}
}
//-->
</script>
Instead of a submit button, use TYPE="Button" and add onClick="CheckEmail()" to the tag.
<added>
Note that the looooooong
"rx = /^[a-z0-9\._]*[a-z0-9_]@[a-z0-9] ... [a-z0-9\-\.]*[a-z0-9]\.pro$/i;"
statement has to be on the same line!
</added>
(edited by: DrDoc at 4:10 pm (utc) on April 15, 2002)
If someone has e-mail validation and I don't want to give my e-mail I just type nonsense@nonsense.com - there's no way you can check if that's real (in Javascript anyway).
I'm not alone in doing this, well, either I'm not alone in doing this or bill.gates@microsoft.com and mickey.mouse@disney.com are regular visitors to our site!