I’ve seen the Google library libphonenumber, and I’m thinking of using it to format user entered phone numbers on an international website. The end result needs to be consistent as the internal CRM is integrated with the phone system to pull up the correct user account details when a customer phones. The phone system will always contain the international code for that user, even if the call originates from inside the same country as the office.
So, I intend to provide a drop down with international dial codes, then leave the rest of the telephone field as free form, but limited to numerical digits, spaces, brackets and dashes. The entry would then be cleansed by stripping out everything but the digits.
The libphonenumber would do an initial sanity check to determine whether it appears to be a valid number, then convert it into the correct international format.
I presume separating area codes and subscriber numbers separately would be overkill, but my question is whether to store only the final fully international formatted entry, or to store the international code separately to the rest of the number (e.g. 2 db fields). Is there a legitimate technical reason for doing this, or is it purely a business decision?
Any time you create a field in a database row, there needs to be a business reason for storing that information.
In your example, storing the international dial code separately allows for determining how many customers you have calling from various countries (grouping and summing on the international dial code). Also, you don’t need the international dial code when calling within the same country. So, displaying the phone number without the international dial code may be less confusing to users in most cases.
It would be tough, and probably overkill for most businesses, to break up international phone numbers into separate fields. However, if you had a business reason for doing so, you could break up most phone numbers into area, region, and locality segments. (I’m not familiar with all international phone number formats, so you might have to have additional segments.)