473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

regex Help

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..

thanks in advance
praveen
Oct 7 '07 #1
3 1531
Try this:

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|
\-]*)?)$";

The problem with your extension is, that you allow the hyphen to be
there only once because you have no quantifier specified.
No quantifier means the character has to be there exactly once.

regards, piccante
Oct 7 '07 #2
thanks,
It works for muliple hyphens,
but wont work for various combination of hyphens,underscore,dots like
following

a.********@ssdd.com
ac************@ssdd.com
need any number of hyphes,dots,underscores allowed

thanks,
praveen


"piccante" <ha*********@gmail.comwrote in message
news:11**********************@50g2000hsm.googlegro ups.com...
Try this:

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|
\-]*)?)$";

The problem with your extension is, that you allow the hyphen to be
there only once because you have no quantifier specified.
No quantifier means the character has to be there exactly once.

regards, piccante


Oct 7 '07 #3
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
Oct 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
4
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.