Reputation: 1242
I have the following code to check if user input is a valid email, there might be a few questions already about this but noone seems to validate the PHP function.
/* check if valid email*/
public function isValidEmail($email){
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
return true;
}
return false;
}
If we do a test using this function:
isValidEmail('[email protected]')
This should return false
because characters like ?=
are inside the email address. Is there a stricter way to check email?
Upvotes: 0
Views: 135
Reputation: 31624
The problem here is that ?
and =
are perfectly valid for an email address. From Wikipedia on the RFC controlling email addresses
The local-part of the email address may use any of these ASCII characters:
These special characters: !#$%&'*+-/=?^_`{|}~ (ASCII: 33, 35–39, 42, 43, 45, 47, 61, 63, 94–96, 123–126)
If you're trying to make sure the email address actually exists, just be aware that that path is very difficult
Upvotes: 2