This is a discussion on Email address regular expression within the PHP Language forums, part of the PHP Programming Forums category; I've been using this pattern to verify email addresses: ^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've been using this pattern to verify email addresses:
^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+) But I've recently discovered that addresses with a dash in them won't pass this test. Seems to me they should pass. What's wrong? -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon" Random Precision Productions(tm) 67 Union St. #2D, Winooski, Vt. 05404-1948 USA Sundays, 7-8 pm - Champ 101.3 FM, Colchester; 102.1 FM, Randolph, Vt. ccb@floydianslip.com - AIM: RandomPrec - www.floydianslip.com |
|
|||
|
Craig Bailey wrote:
> I've been using this pattern to verify email addresses: > > ^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+) > > But I've recently discovered that addresses with a dash in them won't > pass this test. > > Seems to me they should pass. [A-Z] = All characters from A to Z, maybe a \- might help ? -- Spam:newsgroup(at)craznar.com@verisign-sux-klj.com EMail:<0110001100101110011000100111010101110010011 010110 11001010100000001100011011100100110000101111010011 011100 11000010111001000101110011000110110111101101101001 00000> |
|
|||
|
In article <Qpbgb.138702$bo1.108744@news-server.bigpond.net.au>,
"127.0.0.1" <newsgroup(at)craznar.com@verisign-sux-ijlkl.com> wrote: > Craig Bailey wrote: > > > I've been using this pattern to verify email addresses: > > > > ^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+) > > > > But I've recently discovered that addresses with a dash in them won't > > pass this test. > > > > Seems to me they should pass. > > [A-Z] = All characters from A to Z, maybe a \- might help ? Aaaahhhh. But a dash doesn't need to be escaped, do it? Are you suggesting a add a dash to the first part of the expression? Like this? ^([0-9a-z-]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+) Of course, that would allow someone to start their address with a dash, which I'm not certain is allowable in real email addresses. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon" Random Precision Productions(tm) 67 Union St. #2D, Winooski, Vt. 05404-1948 USA Sundays, 7-8 pm - Champ 101.3 FM, Colchester; 102.1 FM, Randolph, Vt. ccb@floydianslip.com - AIM: RandomPrec - www.floydianslip.com |
|
|||
|
[ not posted to alt groups ]
Craig Bailey wrote: > I've been using this pattern to verify email addresses: > > ^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+) > > But I've recently discovered that addresses with a dash in them won't > pass this test. > > Seems to me they should pass. > > What's wrong? Doesn't [0-9a-z\.-_] mean: 0 to 9 and a to z and dot to underscore? try [0-9a-z\._-] HTH -- I have a spam filter working. To mail me include "urkxvq" (with or without the quotes) in the subject line, or your mail will be ruthlessly discarded. |
|
|||
|
Hello,
On 10/06/2003 07:16 AM, Craig Bailey wrote: > I've been using this pattern to verify email addresses: > > ^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+) > > But I've recently discovered that addresses with a dash in them won't > pass this test. > > Seems to me they should pass. > > What's wrong? Character ranges that include - must start with that character. Take a look here at this e-mail address validation class that comes with a suitable regular expression besides the server based e-mail verification methods. http://www.phpclasses.org/emailvalidation -- Regards, Manuel Lemos Free ready to use OOP components written in PHP http://www.phpclasses.org/ |
|
|||
|
Pedro wrote:
> Doesn't [0-9a-z\.-_] mean: 0 to 9 and a to z and dot to underscore? Yep. That's dot to underscore in "ASCII collating sequence". "Dot to underscore" matches fifty characters in total, including all uppercase letters, numbers, and a bunch of others -- but not the hyphen! > try [0-9a-z\._-] Or even [\w.-]. ;-) -- Jock |
|
|||
|
On Mon, 06 Oct 2003 11:56:14 -0300, Manuel Lemos <mlemos@acm.org> wrote:
>Character ranges that include - must start with that character. Or end with it. -- Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk) Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space) |
|
|||
|
Craig Bailey wrote:
> Aaaahhhh. But a dash doesn't need to be escaped, do it? Not necessarily. But in its current position, yes, because it's indicating a range. The *hyphen* may only be left unescaped "where it cannot be interpreted as indicating a range". > Of course, that would allow someone to start their address with a dash, > which I'm not certain is allowable in real email addresses. I am certain it is. See RFC 2822 for details, especially section 3.4.1. -- Jock |
|
|||
|
John Dunlop wrote:
> Or even [\w.-]. ;-) that will match (in some locales) "josécuña" ps. hope that gets out ok, in HTML I'd write it as josécuña -- I have a spam filter working. To mail me include "urkxvq" (with or without the quotes) in the subject line, or your mail will be ruthlessly discarded. |
|
|||
|
Pedro wrote:
> John Dunlop wrote: > > > Or even [\w.-]. ;-) > > that will match (in some locales) "josécuña" Ah. Well spotted! I forgot what the intended use was, and concentrated on the one part. Thanks. > ps. hope that gets out ok It did. -- Jock |