Ibrahim Azhar Armar
Ibrahim Azhar Armar

Reputation: 25745

PHP - Regular Expression For Custom Phone Number Format

I need to validate phone number with following rule

I am facing difficulty to construct the correct regular expression, so far I only have preg_match('/^\+\d+$/', $value) and this is definitely not working. Any help in here is appreciated.

Thanks.

Upvotes: 0

Views: 353

Answers (3)

Zbigniew Pretki
Zbigniew Pretki

Reputation: 21

Your regular expression should look like this one:

^\+(352|91|33|49|32)(\d{8,15})$

This page https://regex101.com/ is very helpful for verify and describing regular expressions.

Upvotes: 1

linden2015
linden2015

Reputation: 887

Must be minimum 8 characters and maximum 15

I'm assuming this is total count.

Pattern:

^\+(?=\d{8,15}$)(?:32|33|49|91|352)\d+$

^               // start of line
\+              // a plus
(?=\d{8,15}$)   // look ahead and assert 8 to 15 digits must match
(?:             // grouped alternation (uncaptured)
32|33|49|91|352 // alternations
)               // end of group
\d+             // 1 or more digits
$               // end of line
  • Flags: g, m
  • Steps: 30

Demo

Upvotes: 1

marvel308
marvel308

Reputation: 10458

you can do it using the regex

^\+(?:(?:91)|(?:49)|(?:3(?:52)|3|2))\d{8,15}

Upvotes: 1

Related Questions