[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Random passwords and E-mail regex
> Regular expression for E-mail address checking - here's what I came up
> with. I have not tested it yet, and am not extremely familiar with
> regexes. Anyone want to take a look and see if it can be improved upon?
>
> if (!ereg("^\w+@\w+\.\w+$", $email))
>
> (this is PHP remember, not Perl. Hopefully the regex syntax is the
> same)
>
The way to do this is to just use the perl module Net::DNS to do an MX lookup
on the stuff right of the @ sign. If that works, the right part is verified.
The stuff on the left is a lot more free form. You have to allow just about
anything printable, because of all of the non RFC compliant mailers out there.
The perl regular expression implemention is a huge superset of the most
commonly used library from Henry Spencer, 'Version 8 Regular Expressions.'
I don't think any language even comes close.
As far as how to use a perl module from PHP, I suspect there are a few options.
Worst case is writing a separate perl script which your PHP script calls as
a shell. Or maybe there's a PHP DNS module.
If you still want to do some very loose validation without doing a MX lookup,
I'd suggest looking at the DNS RFC. I don't know the number off hand, but
I could find out.
Cheers.
-Dana
-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,
Dana M. Diederich Phone: 1.501.855.7175
SMTP: dana@realms.org HTTP: http://realms.org/ ICQ: 16433785
Snail Mail: 19 Leicester Drive, Bella Vista, Ar 72714, USA
`Berkeley invented LSD and Unix, and I don't think that's a coincidence.'