Max length in filter validate email function

503 Views Asked by At

I am using the PHP function FILTER_VALIDATE_EMAIL to validate email addresses entered by the users. And my code is as follows.

private function _isValidEmail($email){
  if(!filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
  else return true;
}

If I try to enter a email address that is equal to 254 characters, the server stops responding & my browser (chrome) says this webpage is not available. I am testing this on a local machine using WAMP server 2.2. All the other pages in the website is working. but emails that are less than 254 seems to be working just fine.

My default charset is set to UTF-8, does this have a effect or is there anything else wrong.

1

There are 1 best solutions below

0
On

A bit offtopic, but you can optimise your function like that:

private function _isValidEmail($email) {
    return (bool)filter_var($email, FILTER_VALIDATE_EMAIL);
}