0

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('some?=Wrong@mail.com') 

This should return false because characters like ?= are inside the email address. Is there a stricter way to check email?

Machavity
  • 30,841
  • 27
  • 92
  • 100
sdfgg45
  • 1,232
  • 4
  • 22
  • 42

1 Answers1

2

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

Community
  • 1
  • 1
Machavity
  • 30,841
  • 27
  • 92
  • 100