email validation strings

email validation strings

am 25.10.2007 16:13:22 von jp2code

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

Re: email validation strings

am 25.10.2007 18:30:40 von Tim Slattery

"jp2code" wrote:

>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 abc@xyz.com or abc@[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)
Slattery_T@bls.gov
http://members.cox.net/slatteryt

Re: email validation strings

am 25.10.2007 20:30:17 von jp2code

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 abc@xyz.com or abc@[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)
> Slattery_T@bls.gov
> http://members.cox.net/slatteryt