phpregexphone-number

12-digit regex for phone number


I am trying to get a regex for a phone number with exactly 12 digits in the format: +############.

The code I am trying to use is ([+]?)\d{12}(\d{2})?$, but no luck.


Solution

  • Try this:

    ^\+\d{12}(\d{2})?$
    

    You needed to escape the plus sign

    Regex101 Demo