By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,749 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,749 IT Pros & Developers. It's quick & easy.

email validation strings

P: n/a
I've got a couple of strings I use to validate emails.

I have no idea what either of them do or what they mean! I found them, they
work, so I use them!

Could somebody let me know what these mean? My guess is that the longer
string is better, simply because it tests more thoroughly, but I could be
mistaken.

String1 =
""^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$""

String2 = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$"

Thanks!
~Joe
Oct 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"jp2code" <poojo.com/mailwrote:
>I've got a couple of strings I use to validate emails.

I have no idea what either of them do or what they mean! I found them, they
work, so I use them!

Could somebody let me know what these mean? My guess is that the longer
string is better, simply because it tests more thoroughly, but I could be
mistaken.

String1 =
""^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$""

String2 = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$"
They are regular expressions. If you don't know what those are, look
here: http://www.regular-expressions.info/quickstart.html

The first looks for any combination of letters, digits, hyphens, and
dots followed by @, followed by either an IP address surrounded by
square brackets, or the more familiar domain name. So it would accept
either ab*@xyz.com or ab*@[123.222.11.143], which are both legal email
addresses.

The second is simpler. "\w" is a "word" character (which I think is
letters or digits), so it's at least one of these, followed by any
combination of "word character", hyphen, plus sign, dot, ending with
at least one "word character". Then @, then a domain name (less
rigorously scanned then in the first RE.

So the first one allows IP addresses behind the @ sign, which is legal
but *very* rare. Both, IMHO, will catch 99% of malformed email
addresses.

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
http://members.cox.net/slatteryt
Oct 25 '07 #2

P: n/a
Thanks Mr. Slattery!

I knew they were "regular expressions," but they were a lot more complicated
looking that the standard [0-9] or [A-Z] that I've ever had to use in the
past.

Regards,
~Joe

"Tim Slattery" wrote:
They are regular expressions. If you don't know what those are, look
here: http://www.regular-expressions.info/quickstart.html

The first looks for any combination of letters, digits, hyphens, and
dots followed by @, followed by either an IP address surrounded by
square brackets, or the more familiar domain name. So it would accept
either ab*@xyz.com or ab*@[123.222.11.143], which are both legal email
addresses.

The second is simpler. "\w" is a "word" character (which I think is
letters or digits), so it's at least one of these, followed by any
combination of "word character", hyphen, plus sign, dot, ending with
at least one "word character". Then @, then a domain name (less
rigorously scanned then in the first RE.

So the first one allows IP addresses behind the @ sign, which is legal
but *very* rare. Both, IMHO, will catch 99% of malformed email
addresses.

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
http://members.cox.net/slatteryt

Oct 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.