I want to to write a matching method in php that allows me to match phone numbers.
The case I have is that I want to build an app that will pull phone contact numbers from Android devices, in the backend, it will match the phone contacts with current app users, and if there are matching, then add these users as friends, similar to how whatsapp is doing when matching phone contacts with users who have whatsapp app in their devices.
The issue I am having right now is how I can write a RegEx that can match phone numbers with/without country code or leading zeros.
In the app, I am asking for user country and phone number, so for example a friend of mine entered these values : Country : Jordan (+962) Phone Number : 799633999 This in the backend will be stored as +962799633999
If we assume that I am storying my friends number as 0799633999, what is the regEx that I can use that will match 0799633999 with +96279963999 ?
Your regex is #(\+\d+|0)(\d{9})$#
You don't do this with regex. Truncate your leading zero, and country code and do regular string comparation.
If contacts can be from various countries, then add country code of one for whom you are looking friends for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With