I'm building a project with Laravel 7.28. I get plain (without country code) phone numbers from the form. I wonder whether to get the country code of phone numbers or not. I searched the web but all I find is phone validation with country code. Is there an API for this?
Asked
Active
Viewed 1,887 times
1 Answers
0
// You will find all country list on this website https://countrycode.org/
//At first you add all the Country Code in String file "CountryCode.strings" with format like below
//"US" = "+1";
//"IN" = "+91";
//Now in the code please use below option to capture country on depending on device located country.
//You must remember some time Device bought from US or Other Countries will give your code value as purchased country so you need to check in the =>Settings of device in =>General =>Language & Region=> Region = India enter image description here
let code:String = Locale.current.regionCode!
if (code.count > 0) {
let countryCode = NSLocalizedString(code, tableName: "CountryCode", bundle: .main, value: "", comment: "")
print(countryCode)
//Do your stuff here
}

sandydhumale
- 11
- 3
-
@sandyhumale but I don't have the country code. should I check validation for each country code? – jigsaw075 May 26 '21 at 09:22
-
You must take the country code as it's really important when your application will be used by NRI. You can ask them to enter country code or you pull them from your String Files. Or you can show them at the confirmation screen you user Sign-Up. Please let me know if you still have something to share or discuss. – sandydhumale May 27 '21 at 09:00
-
Please let me know if you require anything? Including code level support. – sandydhumale May 27 '21 at 12:46