-1

I'm trying to validate phone numbers and am struggling with this code. When I input a mobile number(0-9) with a length of either 10 or 11 I get invalid mobile number. Any ideas?

if (!preg_match('[0-9]{10,11}', $mobileNumber)) {
    echo("invalid mobile number");
    exit();
}
PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44
CJava
  • 189
  • 1
  • 5
  • 15

1 Answers1

2

I believe you're missing the regex delimiters:

if (!preg_match('/[0-9]{10,11}/', $mobileNumber)) {
    echo("invalid mobile number");
    exit();
}
Harry
  • 2,429
  • 4
  • 21
  • 26