Hello friends today i am telling you how to validate Email addresses using Regular Expressions.I hope you all are aware of Regular expressions,you have a little knowledge about Regular Expressions before reading this article.If you don't know anything about it then click this link.
http://www.learning-tutorials.blogspot.com |
Now try to understand the following validation process.
Before validating Email address you have to know something about it.
The local-part (the part before the "@" character) of the e-mail may use any of these ASCII characters:
- Uppercase and lowercase letters
- The digits 0 through 9
- The characters , ! # $ % & ' * + - / = ? ^ _ ` { | } ~
- The character "." provided that it is not the first or last character in the local-part
The domain part of the address is much easier to handle. The dot separated domain labels can only include letters, digits and hyphens.
Regular Expression is:
^[a-z 0-9_\+-]+(\.[a-z 0-9_\+-]+)*@[a-z 0-9-]+(\.[a-z 0-9-]+)*\.([a-z]{2,4})$
Explanation:-
The first part,^[a-z 0-9_\+-]+ means that the address has to start with letters
a-z
, numbers 0-9
or characters "_", "+"
or "-"
The final "+" means there must be 1..n of these characters.For example:learning12,doon+123 etc.
The regexp continues with (\.[a-z 0-9_\+-]+)* . It means that the first characters defined before can be followed with a period "." and after that with the same set of characters than before the period. Because characters "." and "+" have special meaning in regexps they must be escaped with a backslash. The final
*
means there must be 0..n of these sequences.For example: doon.geu+edu
After these characters there must be a single "@" character. It must be followed by a domain label that consist of letters, numbers and hyphens. There can be 1..n domain labels separated with a period. The first label (without the period) is defined by [a-z 0-9-]+ After this there can be 0..n similar sequences starting with a period. This is defined as (\.[a-z 0-9-]+)*
\.([a-z]{2,4})$ means at the end string is followed by 2..4 letters.
Also see this:
***Thanks Friends***
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteRegards,
Dot Net Course in Chennai | Asp.Net Training in Chennai | Best Dot Net Training in Chennai
Best Selenium Training Institute in Chennai | Selenium Coaching Institute in Chennai | Selenium Training in Chennai
Software Testing Course in Chennai | Best Software Testing Training Institute in Chennai With Placement
Core Java Training in Chennai | Java Course and Certification | Java Training Institute in Chennai
PHP Training in Chennai | PHP Training Institute in Chennai | PHP Course in Chennai