E
E
Empty User2015-09-02 18:01:32
PHP
Empty User, 2015-09-02 18:01:32

How to format phone numbers?

There is a list of numbers, and you need to somehow store all these numbers in the same format. For example, the API can receive numbers in the following formats:
+7 777 777 77 77
8 777 777 77 77
777 777 77 77
And the whole thing should be stored in this form as one number - 77777777777
How does iOS do it? For example, if you dial any of these numbers, then in any case we get to one.
It doesn't matter where to process numbers, even on the server (PHP), even on the front (Swift, Objective-C)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
s0L, 2015-09-03
@dimash07

https://github.com/googlei18n/libphonenumber
there are links to ports for different languages

N
Nikita Kamenev, 2015-09-02
@NickStone

How I do it for the web:
I put regexp on the input itself, which formats the number according to the format I need, and then I check it already on the server, if the number is suddenly replaced by some TamperData.
On the server side, I remove all dashes, brackets and spaces. Next, I check the size of the room, there are two options with or without 7/8. Everything, if it satisfies all the conditions - we write to the database.

I
IsaevDev, 2015-09-02
@IsaevDev

Well, if for different countries, it is necessary that the client first selects a country from the list, and then enters the number without a code.
This is +7 (xxx) xxx-xx-xx in Russia, and somewhere, for example, +345 (xxxx) xxx-xxx
I think there are ready-made plugins with a list of countries

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question