Storage of telephone numbers in a database
Hi,
I want to log in via e-mail and telephone number.
How to store the phone number?
I was thinking about code + number phone, unfortunately I have a problem with detecting what is a number and what is a code.
The user has one input, if the system detects that he has given his phone number, he must add a code depending on the culture.
There are a few problems:
1.) The user must enter the telephone number code each time
2.) When he enters the phone number alone, there may be a problem with sending the verification message, what if the user is in Poland and has a number from Germany?
Is there any solution ready for this? The topic seems to be very difficult.
22 Replies
Store the country code, and store the number, in separate columns, I'd say
in theory, the first numbers are the country followed by the telephone number.
It is very difficult
Well, store them separately
Have a dropdown for country codes
Then a field to input the rest of the number
I did something like that
Now the question is whether plus matters, write it as an int or as a string.
+48 or 48
Also the question of whether a phone number is always an int, I saw a dash once
eg: 88-888 888 88
I would definitely not recommend storing phone number as an integer
Not just because it would lose any leading zeros, but it also isn't really in a more useful format stored as an integer
That's true, eg +44 003 323 412
I think this form is correct? @Auger
I'd probably store both as strings
Maybe even store the code as an enum, or in a separate table, since there's only so many valid country codes
That'd be useful in-case you wanted to know the country the code belongs too. Might make it easier for the user to find as well.
Yeah, so you can just type
Brazil
in the dropdown and it finds the country code for youI didn't see any with a leading 0 for the country code, but I do see dashes are possible.
That's how I see it set up everywhere
Country codes always start with a
+
and consist of, I believe, 0-3 digits
And yeah, they can contain dashes
Like Anguilla, 1-264
Or Guernsey, 44-1481
multiple
GitHub
SimPlanner/ISO3166.cs at master · mcshaz/SimPlanner
Web App to coordinate running a hospital simulation program - development phase - SimPlanner/ISO3166.cs at master · mcshaz/SimPlanner
Yeah, just noticed Puerto Rico
1-787, 1-939
My general rule of thumb is that if you're not sure if something should be an
int
or not, ask yourself, does it make sense if one is greater than or less than one another, and are you trying to do any math with it?
Strings can still be ordered by their ASCII values for sorting, so it doesn't need to be an int for that reason either.I'd store it as
Postgres array columns would come useful
Then you'd have
Now the question is whether the area code is assigned to the phone number or does the operator allow many?
For example, calling one number twice with a different code will I get through.
Not sure on that
If this does not allow, the code should be hard-coded in a string.
I'd say area code should be a part of the number