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
  • 3,705
  • 8
  • 33
  • 78

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
  • 14,792
  • 4
  • 23
  • 42