0

With php preg_match , I found this regular expression for phone number code (such as +61)

$res = preg_match('/(\+\d{1,3})/', '+99999999'); // must return false

But it returns true. Maximum length must be 3. I mean (+999)

Any idea?

Vahid Najafi
  • 4,654
  • 11
  • 43
  • 88

1 Answers1

1

PHP code demo

Regex: '/^(\+\d{1,3})$/

Change regex: /(\+\d{1,3})/ to /^(\+\d{1,3})$/

<?php
$res= preg_match('/^(\+\d{1,3})$/', '+99999999',$matches);
print_r($matches);
Sahil Gulati
  • 15,028
  • 4
  • 24
  • 42