2

Possible Duplicate:
email address validation

Hello. I have this function to validate an email address

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

It works well with domain zones like .com, .us etc, which contain from 2 to 3 symbols after a dot. My question is: is it important to include such zones as .info or .travel with length more than 3 symbols and should I worry about multiple .co.uk etc.? How to improve the function for these needs?

Community
  • 1
  • 1
Denis Bobrovnikov
  • 347
  • 1
  • 4
  • 11
  • 5
    1. [`eregi` is deprecated](http://de3.php.net/manual/en/function.eregi.php) 2. yes, 3. use [`filter_var`](http://de3.php.net/manual/en/function.filter-var.php) 4. [it's a duplicate](http://stackoverflow.com/search?q=php+email+validation) – Gordon Feb 05 '11 at 11:35

1 Answers1

6

there is a native function in php to do this, test it and see if it fits your needs:

var_dump(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));

P.S: Isn't eregi() deprecated?

greg0ire
  • 22,714
  • 16
  • 72
  • 101