如何判断电子邮件的地址格式是否正确?
第一种办法:
<%
Function IsValidEmail(Email)
ValidFlag = False
If (Email <> "") And (InStr(1, Email, "@") > 0) And (InStr(1, Email, ".") > 0) Then
atCount = 0
SpecialFlag = False
For atLoop = 1 To Len(Email)
atChr = Mid(Email, atLoop, 1)
If atChr = "@" Then atCount = atCount + 1
If (atChr >= Chr(32)) And (atChr <= Chr(44)) Then SpecialFlag = True
If (atChr = Chr(47)) Or (atChr = Chr(96)) Or (atChr >= Chr(123)) Then SpecialFlag = True
If (atChr >= Chr(58)) And (atChr <= Chr(63)) Then SpecialFlag = True
If (atChr >= Chr(91)) And (atChr <= Chr(94)) Then SpecialFlag = True
Next
If (atCount = 1) And (SpecialFlag = False) Then
BadFlag = False
tAry1 = Split(Email, "@")
UserName = tAry1(0)
DomainName = tAry1(1)
If (UserName = "") Or (DomainName = "") Then BadFlag = True
If Mid(DomainName, 1, 1) = "." then BadFlag = True
If Mid(DomainName, Len(DomainName), 1) = "." then BadFlag = True
ValidFlag = True
' 格式正确返回Ture。
End If
End If
If BadFlag = True Then ValidFlag = False
' 格式不正确返回False。
IsValidEmail = ValidFlag
End Function
%>
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
第二种办法:
<%
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
next
if InStr(names(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
%>
第三种办法,用下面这个函数进行判断。它会检查邮件地址是否含有“@”,以及“.”是否在“@”后面:
function isEmail(pInString)
lAt = False
lDot = false
for x = 2 to len(pInstring)-1
if mid(pInString,x,1) = "@" then lAt = True
if mid(pInString,x,1) = "." and lAt = True then lDot = True
next
if lAt = True and lDot = True then
isEmail = True
else
isEmail = False
end if
end function
[1]
上一篇:如何做一个文本搜索?
栏 目:编程问答
下一篇:如何实现点击数的计算?
本文标题:如何判断电子邮件的地址格式是否正确?
本文地址:https://www.xiuzhanwang.com/a1/bianchengwenda/12106.html
您可能感兴趣的文章
- 01-11如何实现点击数的计算?
- 01-11如何做一个文本搜索?
- 01-11如何实现网上考试?
- 01-11如何实现全文检索?
- 01-11如何用POP3接收电子邮件?
- 01-11如何使用表单发送电子邮件?
- 01-11如何在线更改密码?
- 01-11如何取回已忘记的密码?
- 01-11如何做一个随机密码产生器?
- 01-11如何将产生的密码记录并发送给用户并通过点击链接激活?
阅读排行
本栏相关
- 01-11如何实现点击数的计算?
- 01-11如何做一个文本搜索?
- 01-11如何判断电子邮件的地址格式是否正
- 01-11如何实现全文检索?
- 01-11如何实现网上考试?
- 01-11如何使用表单发送电子邮件?
- 01-11如何用POP3接收电子邮件?
- 01-11如何取回已忘记的密码?
- 01-11如何在线更改密码?
- 01-11如何做一个随机密码产生器?
随机阅读
- 04-02jquery与jsp,用jquery
- 01-11ajax实现页面的局部加载
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 01-10SublimeText编译C开发环境设置
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 01-10delphi制作wav文件的方法
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 01-10C#中split用法实例总结