note 101609 deleted from function.preg-match by danbrown
| From: | danbrown@php.net | Date: | Thu, 30 Dec 2010 05:47:05 +0000 |
| Subject: | note 101609 deleted from function.preg-match by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175323@lists.php.net to get a copy of this message | ||
Note Submitter: Paperweight
----
That's not a real world email address sanitizer, THIS is a real world email address sanitizer.
Someone took a week to figure it out a few years back ;)
<?php
function san_email($email){
$email = preg_replace('/[^a-z0-9-_\+\.@]/i', null, $email);
if(preg_match("/^([a-z0-9]([a-z0-9_-]*\.?[a-z0-9])*)(\+[a-z0-9]+)?
@([a-z0-9]([a-z0-9-]*[a-z0-9])*\.)*([a-z0-9]([a-z0-9-]*[a-z0-9]+)*)
\.[a-z]{2,6}$/i", $email)){
return $email;
}
}