电子邮件验证服务器端

时间:2011-08-04 04:37:38

标签: vbscript asp-classic

我正在尝试验证电子邮件,但我的代码不允许一些情况..

代码

pvm = "bw.stack@domain.com" does not work
pvm = "user@gmail.com" - works

If Len(pvm) < 5 OR NOT Instr(1, pvm, " ") = 0 OR InStr(1, pvm, "@", 1) < 2 OR InStrRev(pvm, ".") < InStr(1, pvm, "@", 1) Then
    blnEmailOKREG = False
        Else
    blnEmailOKREG = True 
End If

1 个答案:

答案 0 :(得分:2)

这是一个相当不错的电子邮件地址验证。请注意,虽然很难获得完全“全知”的验证。

' Function IsValidEmail
' Method checks if a string value is a valid email adress
' @Param val: <string> String containing email adress.
' @RETURN: True / False
Public function IsValidEmail(ByRef val)
    IsValidEmail = RegExTest(val,"^[_a-zA-Z0-9-""'\/]+(\.[_a-zA-Z0-9-""'\/]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$")
end function

_

Public function RegexTest(str, pattern)
    dim m_objRegex 

    set m_objRegex = New RegExp
    m_objRegex.Pattern = pattern
    m_objRegex.Global = True
    RegExTest = m_objRegex.Test(str)

    set m_objRegex = nothing 
End function