note 76615 added to function.preg-match

From: Date: Mon, 23 Jul 2007 10:22:50 +0000
Subject: note 76615 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-128834@lists.php.net to get a copy of this message
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. ---- Server IP: 80.81.171.181 Probable Submitter: 213.139.171.67 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/76615 Del: integrated -- https://master.php.net/note/delete/76615/integrated Del: useless -- https://master.php.net/note/delete/76615/useless Del: bad code -- https://master.php.net/note/delete/76615/bad+code Del: spam -- https://master.php.net/note/delete/76615/spam Del: non-english -- https://master.php.net/note/delete/76615/non-english Del: in docs -- https://master.php.net/note/delete/76615/in+docs Del: other reasons-- https://master.php.net/note/delete/76615 Reject -- https://master.php.net/note/reject/76615 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128834) next »