IsValidEmail = true
names = Split(email, "@")
if UBound(names) < > 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) < = 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) < = 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") < = 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i < > 2 and i < > 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false
end if
if (theForm.mail.value == "")
{
alert("留个邮箱吧,以后忘记密码有用哦!");
theForm.mail.focus();
return (false);
}
if (theForm.mail.value.length > 100)
{
window.alert("哇~~这信箱也太长了吧?有30个字都很夸张啦!^_^");
return false;
}
var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
var re = new RegExp(regu);
if (theForm.mail.value.search(re) != -1) {
return true;
} else {
window.alert ("嗯,这信箱怎么有点怪怪的呢?^_^")
return false;
}
这样一般就可以了:
function isEmail(vEMail)
{
var regInvalid=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
var regValid=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
return (!regInvalid.test(vEMail)&®Valid.test(vEMail));
}