Email validation serverside

非 Y 不嫁゛ 提交于 2020-11-29 02:55:38

问题


I'm trying to validate emails but my code is not allowing a few scenarios..

Code

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:


Here is a fairly good valiation for email addresses. Please note though that its hard to get a completely 'all-knowing' validation.

' 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


来源:https://stackoverflow.com/questions/6936251/email-validation-serverside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!