用函数也可以啊 Public Function IsEmail(ByVal email as string) as boolean dim names() as string dim name as string dim i as integer dim c as string
names = split(email,"@")
if Ubound(names) <> 1 then return false end if for each name in names if Len(name) <= 0 then return false end if for i = 1 to Len(name) c = Lcase(Mid(name, i, 1)) if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then return false end if next if Left(name, 1) = "." or Right(name, 1) = "." then return false end if next if InStr(names(1), ".") <= 0 then return false end if i = Len(names(1)) - InStrRev(names(1), ".") if i <> 2 and i <> 3 then return false end if if InStr(email, "..") > 0 then return false end if
Public Function IsEmail(ByVal email as string) as boolean
dim names() as string
dim name as string
dim i as integer
dim c as string
names = split(email,"@")
if Ubound(names) <> 1 then
return false
end if
for each name in names
if Len(name) <= 0 then
return false
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
return false
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
return false
end if
next
if InStr(names(1), ".") <= 0 then
return false
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
return false
end if
if InStr(email, "..") > 0 then
return false
end if
return true
end function
在属性里找到RegularExpression,单击...,里面就有email的正则表达式
你对比一下你的函数和别人提供的正则表达式,看看哪个更简洁?^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$