<form name = form1 action = "aa.asp" method = post> <input type = text name = email> <input type = button name = bu value = Submit> </form> <script> function document.all.bu.onclick() { window.execScript("mail = trim(form1.email.value)","VBscript"); if (mail!="") { if (mail.indexOf("@") == -1 || mail.indexOf(".") == -1|| mail.indexOf(" ")!= -1) { alert("不是一个 合法的 E-mail"); return false; } } form1.submit(); } </script>
function IsValidEmail(email) 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 ifend function
function check( form1 ){
if( form1.mailtext.value.length != 0 ){ //Email栏填东西了
//在这里写检查Email格式的方法
}else if(......//检查其它的省略 ){
...
} else {
return true ;
}}
<input type = text name = email>
<input type = button name = bu value = Submit>
</form>
<script>
function document.all.bu.onclick()
{
window.execScript("mail = trim(form1.email.value)","VBscript");
if (mail!="")
{
if (mail.indexOf("@") == -1 || mail.indexOf(".") == -1|| mail.indexOf(" ")!= -1)
{
alert("不是一个 合法的 E-mail");
return false;
}
}
form1.submit();
}
</script>
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 ifend function