0

I'm trying to write a regex that can detect if a user's phone number matches a given string, regardless of formatting (ie. only matching on integer characters).

For example, given the phone number '5555555555', I want the numbers '555-555-5555' and '(555) 555-5555' to be considered a match.

Any ideas?

unsunghero
  • 971
  • 1
  • 10
  • 22
  • It is different than that question in that I'm trying to compare 2 phone numbers, instead of just validating that a phone number is a real phone number. Somewhere in the regex there would be literally be "5555555555", I just have no idea what else would denote to ignore non-integer characters. – unsunghero Sep 18 '14 at 20:35
  • So remove the formatting from the strings that contain them, and then compare the two strings. – Ken White Sep 18 '14 at 20:39
  • The catch is that I'm trying to do this through a rethinkdb query, it has to be done through a regex. It may not be possible, in which I'll just have to remove any formatting when it gets stored in the database, but it would save me a headache if it was possible to do with a regex. – unsunghero Sep 18 '14 at 20:41
  • 1
    It's not pretty, but this return the phone number (only the digits) -- https://gist.github.com/neumino/e04494837b430c7a565c – neumino Sep 18 '14 at 21:32

0 Answers0