0

Possible Duplicate:
Validate Email in php
How to validate an email address in PHP

Till date i have been using

preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^",$email)

But with the introduction of the new Generic Top Level Domain extensions. The domain extension part could go up to 64 characters.

Also in the new gTLD's the introduction of Internationalized Domain Names (IDN), how do you validate the eMail with PHP.

Community
  • 1
  • 1
  • filter_var can be helpful – Bhavik Shah Jan 02 '13 at 14:39
  • 4
    The best bet is not to rely on regex, but instead take the domain name and send DNS query for it. If you receive a satisfactory result, then you have a valid domain name. For email, it's the same thing: take the host part of the email address and request DNS MX rexord for it. If you get a record back, then this is a valid hostname. Naturally, you'll need to do some validation on the username part, but it's much easier. – Aleks G Jan 02 '13 at 14:41
  • @AleksG that's actually verification whereas validation is merely the act of checking it syntactically. A valid domain name may not be connected but still be valid. – Gordon Jan 02 '13 at 14:53
  • @Gordon true enough, however as the OP is interested in checking email addresses, the domain better be connected to something, otherwise email would not be delivered anyway. – Aleks G Jan 02 '13 at 14:57
  • @AleksG yes, though one could also argue that a MX Record does not guarantee a particular email address exists there and most SMTP servers disable VRFY. So technically, you won't know whether an email exists until you sent it. – Gordon Jan 02 '13 at 14:59
  • @Gordon Correct, VRFY is disabled, but in order for an email to be deliverable, the host part must have an MX record. That's why you can verify the host part, but can only validate the username. – Aleks G Jan 02 '13 at 15:00

0 Answers0