0

I'm looking to use either PHP or Regex to check an email string to see if it matches a specific format. The format is :

Any number of characters and numbers, but ending in a fullstop then 1 number and @gmail.com

For example :

test2email.7@gmail.com
anothertest.6@gmail.com
323232.3@gmail.com
Mark
  • 79
  • 1
  • 7

2 Answers2

0

Your question is vague but if you want to check email is correct or not use this:

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    # valid email
}

http://php.net/manual/en/function.filter-var.php

RNK
  • 5,582
  • 11
  • 65
  • 133
  • It looks like the OP wants emails to match a naming convention, `but ending in a fullstop then 1 number and @gmail.com`. – chris85 Feb 03 '17 at 17:34
0

I'm sure someone is going to mark this as a duplicate, as a quick SO search for "email regex" turns up several results, as does a Google search. Some of your best bets are this thread and perhaps this one, and this article on regular-expressions.info. But, to quote an answer from the first thread:

This question is asked a lot, but I think you should step back and ask yourself why you want to validate email adresses syntactically? What is the benefit really?

  • It will not catch common typos.
  • It does not prevent people from entering invalid or made-up email addresses, or entering someone else's address.

If you want to validate that an email is correct, you have no choice than to send an confirmation email and have the user reply to that. In many cases you will have to send a confirmation mail anyway for security reasons or for ethical reasons (so you cannot e.g. sign someone up to a service against their will)

Community
  • 1
  • 1
alanlittle
  • 460
  • 2
  • 12