-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,860
  • 3
  • 30
  • 44
CJava
  • 179
  • 1
  • 4
  • 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,212
  • 3
  • 20
  • 25