欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp email邮箱地址验证正则表达式

程序员文章站 2022-01-01 12:26:02
上篇文章我们用字符串查找的方法实现了,有可能比较喜欢正则表达式的朋友,这里也给出相应的代码。方法一 复制代码 代码如下: public function chkmail(b...

上篇文章我们用字符串查找的方法实现了,有可能比较喜欢正则表达式的朋友,这里也给出相应的代码。
方法一

复制代码 代码如下:

public function chkmail(byval email)
dim rep,pmail : chkmail = true : set rep = new regexp
rep.pattern = "([.a-za-z0-9_-]){2,10}@([a-za-z0-9_-]){2,10}(.([a-za-z0-9]){2,}){1,4}$"
pmail = rep.test(email) : set rep = nothing
if not pmail then chkmail = false
end function

邮箱地址验证二
复制代码 代码如下:

<%
function isemail(strng)
isemail = false
dim regex, match
set regex = new regexp
regex.pattern = "^w+((-w+)|(.w+))*@[a-za-z0-9]+((.|-)[a-za-z0-9]+)*.[a-za-z0-9]+$"
regex.ignorecase = true
set match = regex.execute(strng)
if match.count then isemail= true
end function
%>

方法三
复制代码 代码如下:

public function isemail(byval pstring)
dim plt,pgt : plt = false : pgt = false
for x = 2 to len(pstring) - 1
if mid(pstring,x,1) = "@" then plt = true
if mid(pstring,x,1) = "." and plt = true then pgt = true
next
if plt = true and pgt = true then
isemail = true
else
isemail = false
end if
end function
%>

我们来看看验证一的实例使用方法
复制代码 代码如下:

if chkmail(admin@jb51.net) = true then
response.write "格式正确"
else
response.write "格式有误"
end if