0

I have a php regular expression for email formatting. I used this code below

if ( !(preg_match('/^\w+@[\w.\-]+\.[A-Za-z]{2,3}$/', $email)) ) : 
$err_email1 = "<div class = 'error'>Sorry, the email is not formatted         properly</div>";
$formerrors = true;

However, it doesn't work when there is a period in the email. i.e. John.Smith@mydomain.com. It works fine with JohnSmith@mydomain.com so I know it's the second period.

How can I modify the code so it works with 2 period? I tried a number of variations but didn't have success.

If you have a good php regular expression site, I am all eyes.

Thanks

kipper
  • 1
  • 2
  • PHP has a built-in regex available per `filter_var()` and `FILTER_VALIDATE_EMAIL` which is a lot more real-world-email-address-compliant. – mario Aug 20 '15 at 03:13

1 Answers1

0

Try this

/^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$/

kayleighsdaddy
  • 670
  • 5
  • 15
  • Thank you. It worked. I believe – kipper Aug 21 '15 at 16:40
  • It worked, thank you. For the benefit of others, I beleive means [a-z0-9_.-] (to the left of the @ sign) means you can have any number of dots. – kipper Aug 21 '15 at 16:40
  • Thank you. For the benefit of others it is the [a-z0-9_.-] (to the left of the @ sign) means you can have any number of dots. Many thanks. – kipper Aug 21 '15 at 16:41