asp IsValidEmail 验证邮箱地址函数(email)
程序员文章站
2022-06-05 12:18:16
复制代码 代码如下:'******************************************** '函数名:isvalidemail '作 用:检查email...
复制代码 代码如下:
'********************************************
'函数名:isvalidemail
'作 用:检查email地址合法性
'参 数:email ----要检查的email地址
'返回值:true ----email地址合法
' false ----email地址不合法
'********************************************
public function isvalidemail(email)
dim names, name, i, c
isvalidemail = true
names = split(email, "@")
if ubound(names) <> 1 then isvalidemail = false: exit function
for each name in names
if len(name) <= 0 then isvalidemail = false:exit function
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
next
if left(name, 1) = "." or right(name, 1) = "." then isvalidemail = false:exit function
next
if instr(names(1), ".") <= 0 then isvalidemail = false:exit function
i = len(names(1)) - instrrev(names(1), ".")
if i <> 2 and i <> 3 then isvalidemail = false:exit function
if instr(email, "..") > 0 then isvalidemail = false
end function
其它语言可以参考: