Calculation if letter matches regular expression?

So, I'm trying to determine if someone is using a temporary email made by our system. If a user tries to log in using a social account (Twitter / Facebook) and they deny access to email, I generate an email for our system, which is AccountID@facebook.com or AccountID@twitter.com , so an example will be 123456789 @facebook. com This is a temporary email until the user enters a real email address. I am trying to compare this with a regex.

    if (preg_match("/^[0-9]@twitter.com/", Auth::user()->email, $matches)) {
    }

However, I think my regex is wrong. How to check if string format is N Number of digits followed by @ twitter.com or @ facebook.com

+4
source share
2 answers

How to check if string format is N Number of digits followed by @twitter.comor@facebook.com

You can use this regex:

'/^\d+@(?:facebook|twitter)\.com$/'

You use ^[0-9]@one that will have only one digit at startup. In addition, DOT is a special regular expression character that must be avoided. Also, pay attention to using the end anchor $in your anchor to avoid matching unwanted input.

+3
source

ID :

    if (preg_match("/^[0-9]+@(twitter|facebook)\.com/", Auth::user()->email, $matches)) 
    {
       //Your code here
    }
+1

Source: https://habr.com/ru/post/1607534/


All Articles