Re: Email with pregmatch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/27/06, Peter Lauri <lists@xxxxxxxxxxx> wrote:
I found this on google, does this LONG function do anything more then your
preg_match?

i think a combo of what the function does and a few regex's will work.
The issue is more on how idoes it pass all the rfc's on each part of
the address, for a quick reference of rfc's:

 http://en.wikipedia.org/wiki/E-mail_address

An address consists of:
 local@xxxxxxxxxxxxx

so the question is does it pass local tests, which should be rather
simple, the domain part gets rather complcated since you cant predict
at what domain level we are talking about:

 local@xxxxxxxxxxxxxxxxxx
 local@xxxxx
 local@xxxxxxx
 local@xxxxxxxxxx


There is a pcre expression out there somewhere in perl land that is
considered to validate all the rfc requirements of the address and is
about 50 lines worth of regular expressions with a lot of backward
matching and forward matching conditions.

So the only simple logic you can really apply is split on  the @; is
local ok? are each part of the domains valid according to the rfc's.
typically it is safe to say if they put at least two periods in a name
and the characters between those periods are valid chars then it is a
valid input ( of course it doesn't mean it is a valid email)

I suppose the least you want to do is limit addresses people can use so:
 local <~~ assumed invalid (no @), unless you only want local addresses
 local@domain <~~ assumed invalid since there is no tld (unless you
want a local address)
 everything else is valid (as long as it passes all the tests)

So with that you want an expression that allows for:
 (valid_local){1}@(valid_domain.)+(valid_tld){1}

where:
 valid_local = a valid local addres
 valid_domain = a valid domain name
 valid_tld = a valid tld
 . = period (dot)
 {1} = must match once
 + = must have 1, can have more

Making a pcre expression can get complicated, breaking it apart and
validating each section will probably make it easier to deal with.


Curt.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux