Basic Email Validation With VBScript / ASP classic

I need a server side check for basic email address syntax. I will use a regular expression to match the pattern of xxxxx@yyyyy.zzz

 Function GetEmailValidator() 
      Set GetEmailValidator = New RegExp 
      GetEmailValidator.Pattern = "^((?:[A-Z0-9_%+-]+.?)+)@((?:[A-Z0-9-]+.)+[A-Z]{2,4})$" 
      GetEmailValidator.IgnoreCase = True 
End Function 

This is a great function, but how to use it? Well, you test it like so:

Dim EmailValidator : Set EmailValidator = GetEmailValidator()
If EmailValidator.Test(to_email) = False Then ..... execute code for when an invalid email is found

Leave a Reply