0

Possible Duplicate:
PHP email validation

I'm working on this website, where I have to make a register form. I made it work, but then my friend told me, that some email domain names does have hyphens in them, like;

test@test-tester.com

Right now my code look like this:

preg_match("/^[a-zA-Z0-9._\-]\w+(\.\w+)*\@\w+(\.[a-zA-Z0-9._-]+)*\.[a-zA-Z.]{2,6}$/", $_POST["email"]

What I can see, this should work, but it still does not allow the hyphen. Anyone know why?

Community
  • 1
  • 1
Naoness
  • 25
  • 1
  • 4

1 Answers1

1

Regex is always useful, but I prefer to use filter_var to validate emails

http://www.php.net/manual/en/filter.filters.validate.php

if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
    print('valid Email!');
}
else
{
    print('invalid-email =(');
} 
NikiC
  • 100,734
  • 37
  • 191
  • 225