Regular Expressions in VbScript?

后端 未结 5 1320
谎友^
谎友^ 2020-12-18 16:02

Does VbScript have a native implementation for Regex? I need to validate e-mail addresses on an old ASP application.

Any pointers would be great.

5条回答
  •  梦毁少年i
    2020-12-18 16:48

    This example is by AlexCuse from LessThanDot

    Function ValidEmail(ByVal emailAddress) 
    
    'this function will use regular expressions to check an '
    'email address for validity '
    
    'instantiate regex object container, output boolean '
    Dim objRegEx, retVal 
    
    'using late binding, vbscript reference is not required '
    Set objRegEx = CreateObject("VBScript.RegExp") 
    
    '.pattern -looks for a valid email address '
    With objRegEx 
          .Pattern = "^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$" 
          .IgnoreCase = True 
    End With 
    
    retVal = objRegEx.Test(emailAddress) 
    
    'get rid of RegEx object '
    Set objRegEx = Nothing 
    
    ValidEmail = retVal 
    
    End Function
    

提交回复
热议问题