Introduction

Regular Expressions are very much useful for validation checking. It's not a new technology; it originated in the UNIX environment, and is commonly used with the Perl language. Regular expressions are, however, supported by a number of .NET classes in the namespace System.Text.RegularExpressions.

Its rules are same as the finite automata. Information regarding the main special characters or escape sequences that you can use are available in the MSDN.

Regular Expressions for Email Checking

Basic things to be understood in RegEx are:

“*” matches 0 or more patterns.

“?” matches single character.

“^” for ignoring matches.

“[]” for searching range patterns.

The rules for validating email IDs, and some valid and invalid examples are mentioned here:

Email addresses must be start with a letter symbol. And any number of letters or digits or underscore (_) can be appended, and only a single dot (.) is allowed but other symbols and white spaces are not allowed.

The name field of the address must end with either a letter or digit.

If underscore or dote is used then before it, letters or digits must be used for a valid name.

So, we conclude that any validation problems that involve recursion, option, limitation is easier to solve with regular expressions than using other ways (like if-elseif-else, while condition). This can be represented in a state diagram that is very much easier and efficient to express and use.

My next article will be on auto ID generation for any table using stored procedures.

Share

About the Author

I am now working as software engineer in Malaysia. I am from Bangladesh and I have completed my B.Sc (Engg.) in CSE from Rajshahi University of Engineering and Technology (RUET).I spend much time in learning latest technology.

yes friend I also thought so. I could not vaditate my valid Id even. I even not use my regular expression that I have given here.. I use RFC 2822 standard. In this article I just wanted to show how can we make regular expression from finite automata. I made it simple and more specific to yahoo id rule.. this rule is not for hotmail or gmail.. so how can I use this as a standard and general..

I even not use my regular expression that I have given here.. I use RFC 2822 standard. In this article I just wanted to show how can we make regular expression from finite automata. I made it simple and more specific to yahoo id rule.. this rule is not for hotmail or gmail.. so how can I use this as a standard and general..

hi,thanks for your comment. Here I have provide only validation not verification. Here I only emphasison valid yahoo email id input. Checking that valid ID exist or not and what we do if ID does not exist is a matter of varification.

Although your ideas work for the general cases, your regular expression does not cover the RFC spec fully. Linked below is one site of many that publishes a regular expression for email address validation. As you can see, it is not simple by any means.

I disagree, the RFC allows emails which would be invalid if submitted to a mailing list. For instance, if i was sending an email to another machine on my network i need only specify the machine's name: "someone@somebox". while this will work when i send something, it will not work if i want to sign up for a codeproject account.

Saying that this article is "too simple" is too simple in itself. Perhaps an explanation of the RFC further should be included and its corresponding pros/cons. The regular expression derived in this article will cover a good 99.9% of email addresses in use today so perhaps it is a more logical implementation rather than that monolithic one you have pasted.

I think maybe somewhere in the middle might be more appropriate. Nothing irritates me more than when sites won't allow the "+" symbol I can use with my Gmail account, even though it's technically valid.

I agree with you. To the author, please read the following page to understand how to do e-mail validation properly (it quotes the same example as the one given above, but also has some explanation attached):