1
expected_Phone_number: (888) 888-8888
actual_phone_number: (888) 888-8888

How do I use Preg_match to check if the 2 numbers match.(I need to check if the 2 phone numbers match exactly)

user3920295
  • 889
  • 2
  • 13
  • 31
  • What do you mean by exact? Does it mean with the same formatting (like spaces and dashes)? – nisargjhaveri Sep 20 '14 at 21:18
  • Are the strings always going to be in the format (888) 888-8888 ? – Island Wave Sep 20 '14 at 21:18
  • I tried doing preg_match('/^expected_phone_number$/', actual_phone_number) and it returned me '0' saying its not an exact match. I am not sure how to do it. My test case is to match if the phone number in the DOM is exactly the same as the phone number i give in my "expected_phone_number" variable - and yes it has to be in the exact format as what is in the expected - with bracked, spaces and hyphen – user3920295 Sep 20 '14 at 21:35

1 Answers1

1

If php supports \Q .. \E, something like

'~^\Q' . $phone_number_expected . '\E$~';  

otherwise regex escape the phone number

'~^' . preg_quote($phone_number_expected, '~') . '$~';  

or just do a string compare