在做项目过程中拾到一段代码,跟网友共享!
最近,由于赶项目,忙得一塌糊涂!很少来这里光顾各位。
在做项目过程中拾到一段验证EMAIL的代码,在此发出来给大家共项,对初学者特别有帮助。
---------------
验证函数IsValidEmail(email):
Function IsValidEmail(email)
dim names, name, i, c
'Check for valid syntax in an email address.
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
End Function
调用代码:
if not IsValidEmail(Email) then
response.write "<script language='javascript'>"
response.write "alert('填写有错,含有非法字符空格、&<>.等,或者邮件地址不正确!');"
response.write "</script>"
response.end
end if
--------------------------
人类的知识本来就是互相学习
--------------------------