note 53615 deleted from function.preg-match by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:23:09 +0000 |
| Subject: | note 53615 deleted from function.preg-match by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127603@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at swirldrop dot com
----
An imporvement of the regular expression from hackajar <matt> yahoo <trot> com for
e-mail addresses is this:
<?php
if(preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $data)
) return true;
?>
This stops the domain name starting or ending with a hyphen (or a full stop), and limits the domain
to a minimum 2 and a maximum 63 characters. I've also added a full stop in the last character
class to allow for 63-character domain names with a country code like .org.uk.
The 63 character limit is just for the bit before the TLD (i.e. only 'php', not
'.net'). I think this is right, but I'm not totally sure.