getNddPrefixForRegion method
Returns the national dialling prefix for a specific region. For example, this would be 1 for the United States, and 0 for New Zealand. Set stripNonDigits to true to strip symbols like '~' (which indicates a wait for a dialling tone) from the prefix returned. If no national prefix is present, we return null.
Warning: Do not use this method for do-your-own formatting - for some regions, the national dialling prefix is used only for certain types of numbers. Use the library's formatting functions to prefix the national prefix when required.
regionCode
the region that we want to get the dialling prefix for.
stripNonDigits
true to strip non-digits from the national dialling prefix.
getNddPrefixForRegion returns the dialling prefix for the region denoted by regionCode.
Implementation
String? getNddPrefixForRegion(String? regionCode, bool stripNonDigits) {
PhoneMetadata? metadata = getMetadataForRegion(regionCode: regionCode);
if (metadata == null) return null;
String nationalPrefix = metadata.nationalPrefix;
// If no national prefix was found, we return null.
if (nationalPrefix.isEmpty) return null;
if (stripNonDigits) {
// Note: if any other non-numeric symbols are ever used in national
// prefixes, these would have to be removed here as well.
nationalPrefix = nationalPrefix.replaceFirst('~', '');
}
return nationalPrefix;
}