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

2017 年 12 月 20 日3710

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

作者: 字体:[ ] 类型:转载 时间:2010-05-27

刚才说了邮箱验证先可用js来处理,然后再由asp,php来做,下面我来看看一个asp 邮箱地址验证正则表达式全新实例吧。

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

复制代码 代码如下:


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

您可能感兴趣的文章:

Tags:

相关文章

最新评论

0 0