|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-12-09 18:59 UTC] troy at scriptedmotion dot com
Description:
------------
Using filter_var to filter a string containing an email address with no top level domain returns the string instead of false.
For example:
filter_var('t@1', FILTER_VALIDATE_EMAIL);
returns 't@1' instead of false.
Reproduce code:
---------------
filter_var('t@1', FILTER_VALIDATE_EMAIL); // returns 't@1' instead of false.
Expected result:
----------------
false
Actual result:
--------------
"t@1" // a string
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 07:00:02 2025 UTC |
ok you say that's a valid email.. but in a working user environment, using this filter to VALIDATE an email address is unworkable. when users register on my site, i want to validate their email address. if the user enters test@test, it returns as valid. but how on earth does my server know that the users email address .com/.net/.co.uk/.biz etc. so when it tries to send the user an email to validate his email address in order to register on my site, he never receives the email because the server doesn't know where to send it. this means i can't use this filter for its intended purpose of validating an email address. back to using regex and the old PHP 4 methods. either make the filter return as invalid, or add an extra parameter to tell it to validate with a top level domain. ie. filter_var('T@TEST', FILTER_VALIDATE_EMAIL, FILTER_FLAG_TOP_LEVEL) if FILTER_FLAG_TOP_LEVEL is set, then 'test@test' returns invalid, if not, then return valid. problem solved, and i'm sure many users would apreciate it.