note 76615 deleted from function.preg-match by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 22:54:56 +0000 |
| Subject: | note 76615 deleted from function.preg-match by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137370@lists.php.net to get a copy of this message | ||
Note Submitter: Antti Haapala
----
Ne'er try to verify email address by using some random regex you just invented sitting on the
toilet seat. It will not work properly. The proper regex for email validation is something along the
lines of
"([-!#$%&'*+/=?_`{|}~a-z0-9^]
+(\.[-!#$%&'*+/=?_`{|}~a-z0-9
^]+)*|"([\x0b\x0c\x21\x01-\x08\
x0e-\x1f\x23-\x5b\x5d-\x7f]|\\[\x
0b\x0c\x01-\x09\x0e-\x7f])*")@((
[a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+[
a-z0-9]([-a-z0-9]*[a-z0-9]){1,1}|
\[((25[0-5]|2[0-4][0-9]|[01]?[0-9]
[0-9]?)\.){3,3}(25[0-5]|2[0-4][0-9
]|[01]?[0-9][0-9]?|[-a-z0-9]*[a-z0
-9]:([\x0b\x0c\x01-\x08\x0e-\x1f\
x21-\x5a\x53-\x7f]|\\[\x0b\x0c\x0
1-\x09\x0e-\x7f])+)\])".
However, you shouldn't even try that regex. If you do not understand what that regexp does,
then please do not try to write one yourself. If you need a _truly_ _valid_ e-mail address, no
regexp is going to help you - just send a verification message to the user-supplied address with a
link or code the user can paste to verify the address. IF you still WISH - against my recommendation
- to use some validating regexp then *please* just make it warn loudly that the address may be
invalid; do not write code that throws a fatal error outright. I am quite fed up with sites that do
not accept my .name e-mail address, or some other valid, working forms for that matter.