I am trying to write a regex for my code, the regex is used to validate the phone number format, the first two digits should be either 01,04,05,06,07,08,09 followed by a dash (-) and followed by 6 digits only.
I used the following regex: 0[1456789]{1}-[0-9]{6}.
I used the following site to make sure my regex is working correctly: RegExr and I'm testing it on the following 01-123456
However, when I run my code, my function returns as if the number is invalid, which is not.
Here is my code:
function validHomePhone () {
global $home_phone;
$home_phone_regex = "0[1456789]{1}-[0-9]{6}";
return preg_match($home_phone_regex, $home_phone);
}
Why am I getting such results?
/0[14-9]-\d{6}/.