Validating eMail-address via Regular Expressions

Regular expressions are supported via the RegExp object by VBScript since version 5 of the scripting engine:

 Function RegExpTest(sEmail)
   RegExpTest = false
   Dim regEx, retVal
   Set regEx = New RegExp
   ' Create regular expression:
   regEx.Pattern ="^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
   ' Set pattern:
   regEx.IgnoreCase = true
   ' Set case sensitivity.
   retVal = regEx.Test(sEmail)
   ' Execute the search test.
   If not retVal Then
     exit function
   End If
   RegExpTest = true
 End Function

Leave a Comment.