邪恶八进制信息安全团队技术讨论组's Archiver

冰血封情 2004-7-28 17:10

[转载]ASP检测表单输入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

勇敢的风 2005-4-22 01:34

这种方法过时了,或者说根本就不应该有,因为该文章的作者根本不知道正则表达式
如下:
Function CheckExp(strng)
dim regEx,Matches
Set regEx = New RegExp
regEx.Pattern = "(\w)+[@]{1}(\w)+[.]{1}(\w)+"
regEx.IgnoreCase = true
regEx.Global = True
Matches = regEx.test(strng)
CheckExp = matches
End Function

成立则返回true

页: [1]
© 1999-2008 EvilOctal Security Team