Hello praveen,
looking for regex pattern for validating emailid
emailid can have a-z 0-9 - _ . (a to z, 0 ot 9, hyphen,undercore,
dot)
here is a sample which I got from net which doesnt allow hyphen(-)
string
pattern=@"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]
+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
Modified the same t o
string
pattern=@"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]
+)*)*([-][a-z|0-9]+([.][a-z|0-9]+([_][a-z|0-9]+)*)*)?@[a-z][a-z|0-9|]*
\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
it works only for one hyphen (-)
Whats wrong here..
One thing to note is that you shoudn't burn your hands on the perfect regular
expression for a correct emailaddress. If you look at the specs, the possibiities
are endless.
If you do want to take a stab at it, make sure you define a good rule, to
which the address should conform.
One I've seen used, and quite like is
- it begins with a letter
- followed by either a repeating group of
- a group of letters and numbers
- or a -, _, . followed by a group of letters and numbers
- followed by a @
- followed by a genuine domain name
- a letter or a number
- followed either by a repeating group of
- a group of letters and numbers
- or a -, _, . followed by a group of letters and numbers
- followed by a group of
- more than 2 letters
which is easily translated to a regex:
[a-z]([a-z0-9]|[-_.][a-z0-9])+@[a-z]([a-z0-9]|[-_.][a-z0-9])+\.[a-z]+
Keep in mind that this does not account for the new unicode domain names,
email addresses formatted as "your full name"@domainname, em**********@1.1.1.1
and such which are all valid email addresses.
The best way to verify if an email address is correct is trying to send it.
--
Jesse Houwing
jesse.houwing at sogeti.nl