Re: Regex for email validation
| From: | mike | Date: | Wed, 27 Aug 2008 07:31:39 +0000 |
| Subject: | Re: Regex for email validation | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278759@lists.php.net to get a copy of this message | ||
> On 8/27/08, VamVan <vamseevan@gmail.com> wrote:
> Hello Guys,
>
> Does any have a regex for email validation? I need to allow only period and
> underscore in the local part , we would need a @ and .com or watever for
> domain.
php should have a good check built-in.
see http://www.php.net/manual/en/function.filter-var.php
if(!filter_var($var, FILTER_VALIDATE_EMAIL)) {
echo "invalid email";
}
some people also go the extra mile and verify the MX record is valid,
or lookup the MX record and even validate the user exists by querying
the mail server.