MSISDN country code detection -


how can detect country code following msisdn?

cyprus (+357xxxxxxxx) -- 11 digits

finland (+358xxxxxxxxxx) -- 13 digits

serbia (+381xxxxxxx) -- 10 digits

different countries have different number of digits in country code , in msisdn, so, there no way match country code alone entire number.

so, how can country code specific msisdn?

if data present in fixed format: {country_code} {space} {phone_digits}, use string operations (regex, splitting , on) country code part. determine country code represents, should match against list of known country codes - either store these in database or use web service validation.

a possible approach database country codes, , compare manually find match - in case format not consistent. error prone, country codes may differ in length , match wrong one. acceptable approach, if there no other choice, first match longest, , shorter codes - yet there no guarantee invalid matches. avoid issue, consider next suggestion:

if have control on how phone numbers persisted (in database or whatever storage use), i'd advice store country code in separate field. sql database, mean have column country code , phone number. can extract country code absolute certainty , process in whatever way like.


as seen comments, format in question expect api clients provide. if case, should attempt enforce constraints format - make client pass country code separate parameter, or use separator symbol appropriate. if so, end parsing code , determining country. client conform desired format.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -