实现E-mail地址验证的vbs函数代码
2024-07-21 02:15:41
供稿:网友
国内最大的酷站演示中心!
**************************************************
'函数名:isvalidemail
'作 用:检查email地址合法性
'参 数:email ----要检查的email地址
'返回值:true ----email地址合法
' false ----email地址不合法
'**************************************************
function isvalidemail(email)
dim names, name, i, c
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
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
if left(names(1),1) ="+" 0 then
isvalidemail = false
exit function
end if
if right(names(1),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