Checking email address for pattern using Regular ExpressionHere 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.
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.
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
This article is written by plus2net.com team.
Be the first to post comment on this article :