Search code examples
androidstringnumber-formattingphone-numberphonenumberutils

Android compare formatted and unformatted phone number


I have two phone numbers. I want to compare them. One is unformatted and one is formatted, for example: "0501231234", "050-123-1234".

How can I compare them ( String.equals() )?


Solution

  • The android.telephony.PhoneNumberUtils class provides methods to compare phone numbers. The compare(String a, String b) method usually suffices, as it will "return true if they're identical enough for caller ID purposes."