I have a string which I need to verify if it's a Country code. The culture is German. Is there any method that I can call to get a list of Country codes in a German culture without having to type out all the 274 (?) codes myself?
Thanks, Teja.
ID is the two-letter country abbreviation for Indonesia.
The following is a list of countries classified by the international call prefix that needs to be dialled when calling abroad from those countries. 011 – all countries and territories in the North American Numbering Plan: American Samoa. Anguilla.
When you say "country code" I assume you mean the two-letter code as in ISO 3166. Then you can use the RegionInfo constructor to check if your string is a correct code.
string countryCode = "de";
try {
RegionInfo info = new RegionInfo(countryCode);
}
catch (ArgumentException argEx)
{
// The code was not a valid country code
}
You could also, as you state in your question, check if it is a valid country code for the german language. Then you just pass in a specific culture name together with the country code.
string language = "de";
string countryCode = "de";
try {
RegionInfo info = new RegionInfo(string.Format("{0}-{1}", language, countryCode));
}
catch (ArgumentException argEx)
{
// The code was not a valid country code for the specified language
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With