0

I would like to validate if an email address is entered by the user but I don't want to be too strict on it... So I came up with this....

My current if statement with regex:

if (preg_match('^/.+?@.+?\..+$/', $_POST["email"]))

However, I would not work for an email address with multiple periods...

For example:

testing@test.one.com

How can I allow multiple . or periods?

user4244510
  • 79
  • 1
  • 8
  • You can allow any character multiple times by putting the `+` character after them // `a` = `1 "a" character` // `a*` = `0 or more "a" characters` // `a+` = `1 or more "a" characters` // `a{2,5}` = `2 to 5 "a" characters` – h2ooooooo Feb 05 '15 at 18:09
  • possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – Andy Lester Feb 05 '15 at 21:26

1 Answers1

4

I would suggest something far simpler that doesn't require you to reinvent the wheel

if(filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
Machavity
  • 30,841
  • 27
  • 92
  • 100