[UPHPU] Advanced e-mail validation
Mac Newbold
mac at macnewbold.com
Tue Feb 6 17:18:01 MST 2007
Today at 4:52pm, Doug Roy said:
> We use a PHP class for form validation. It includes an e-mail validation
> that checks for the form XXX at XXX.XXX.
>
> My boss wants more (imagine!). Here's he's latest request:
>
> "Please add some additional simple tests to validate the email
> extension. Include as valid: .com, .net, .gov, .info, .biz, .org, .tv "
>
> Does anyone on this list use anything like this? or know of any existing
> PHP class that adds that extra level of e-mail checking?
I haven't tried the pear class that Ray mentioned, but when I do mine, I
check it with a regular expression, then if it passes, check the domain
name against DNS. (The regular expression allows for more than two parts
after the @, so username at host.domain.com works, since that is valid too.)
To check it against DNS, you can use gethostbyname(), checkdnsrr(),
getmxrr(), or use system() or `` to call 'host' on your server. Mine
checks that the domain/hostname after the @ either has an MX record or has
an IP address (either one is valid and works for mail delivery). This
takes it a lot further than simply a list of valid top level domains can,
in terms of the accuracy of the validation, allowing any apparently valid
email domain, and being a little more future-proof as more top level
domains get added.
If you run into trouble, just ask, I know several people on the list have
done similar things.
Mac
--
Mac Newbold MNE - Mac Newbold Enterprises, LLC
mac at macnewbold.com http://www.macnewbold.com/
More information about the UPHPU
mailing list