If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Is PHP confused about FILTER_VALIDATE_EMAIL?

HI

Please consider the following code:

PHP Code:

var_dump(filter_var('a=b@test.com', FILTER_VALIDATE_EMAIL));

Ideally the above email should be invalid and var_dump should return false but the strange thing is when u run this code on the following sites they return non similar results, can anyone tell me whats going on?

What makes you think it's an invalid email address? (You might be surprised what the standard actually allows, though 99.9% or more of in-use email addresses only use a fairly small sub-set of what is allowed.)

It also depends on why you want to filter_var() it in the first place. Syntax checking is often of limited value (at best). If the user enters a syntactically correct email address which is misspelled, it's not of much use. If you reject a valid email address because your regular expression rejects certain edge cases that are, in fact, valid, it's not only of limited use but can actually lose business for you.

This is probably why most site registrations just take whatever the user gives them (often using the enter-it-twice method) and sends an email with a custom link to validate the registration. In other words, the only way to truly know if an email address is completely correct is to use it.

"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation