Checking email address for pattern using Regular Expression

Here we can check the email address for valid or not by using Regular Expression. Note that we are not checking the existence of email address or the domain name associated with it, we are only checking the pattern of the email and it is in acceptable pattern or not.

Every email address will have one name part and another domain part which includes the domain extension. The name part and the domain part is separated by a @ character. In the name part we can't allow special characters other than underscore ( _ ) , Hyphen ( -) and dot ( . ) . So our validation has to take care of this. In the domain name part underscore ( _ ) not allowed and Hyphens ( - ) allowed but they can't be at the starting or ending of the domain name.

We can imitate the regular expression object of VBScript like this.
dim RExp : set RExp = new RegExp
By using this object we can check any string.

Here is the complete code. The output of this is true or false based on the result of validation.

Dim email
dim RExp : set RExp = new RegExp
with RExp
.Pattern = "^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w][^_]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"
.IgnoreCase = True
.Global = True
end with
email= ""
Response.Write RExp.test(email)
Here only characters lower or upper case along with numbers is allowed. The length of the string has to be minimum 3 and maximum 8 char length. Here is some different values of the string ( userid ) for which the validation will pass and output will be True.

It will fail or return False for these values


Be the first to post comment on this article :

Further readings
Introduction to Regular Expression for validating user input
Validating userid and password by using regular expression for user entered data
Validating Email address by using regular expression
Form Handling in ASP, Get and Post methods

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer