0)And(InStr(1,Email,".")>0)ThenatCount= 金钱帮资源网更新日期:2024/9/21" />
网络编程 
首页 > 网络编程 > 浏览文章

如何判断电子邮件的地址格式是否正确?

(编辑:jimmy 日期: 2024/9/21 浏览:3 次 )

第一种办法:

<%

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

%>

 

    第二种办法:

<%
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]

上一篇:如何实现电子邮件的自动发送?
下一篇:如何用变量实现群聊和悄悄话?
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap