MobileNumber.fromCompleteNumber constructor
MobileNumber.fromCompleteNumber({
- required String completeNumber,
Implementation
factory MobileNumber.fromCompleteNumber({required String completeNumber}) {
if (completeNumber == "") {
return MobileNumber(countryISOCode: "", countryCode: "", number: "");
}
// remove white spaces and dashes
completeNumber = completeNumber.replaceAll(RegExp(r'\s+'), '');
completeNumber = completeNumber.replaceAll(RegExp('-+'), '');
try {
Country country = getCountry(completeNumber);
String number;
if (completeNumber.startsWith('+')) {
number = completeNumber
.substring(1 + country.dialCode.length + country.regionCode.length);
} else {
number = completeNumber
.substring(country.dialCode.length + country.regionCode.length);
}
return MobileNumber(
countryISOCode: country.code,
countryCode: country.dialCode + country.regionCode,
number: number);
} on InvalidCharactersException {
rethrow;
// ignore: unused_catch_clause
} on Exception catch (e) {
return MobileNumber(countryISOCode: "", countryCode: "", number: "");
}
}