Search code examples
regexperformancesecurityvalidationfilter-var

Which Method For Verification ? REGEX or filter_var?


What do you think, is there any difference (for performance, security, reliability ) between this methods :

METHOD 1

eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)

METHOD 2

filter_var($email, FILTER_SANITIZE_EMAIL) 
filter_var($email, FILTER_VALIDATE_EMAIL)

Solution

  • Method 2 is clearly easier to understand and more maintainable. The regular expression just looks like line noise.