normalizePhone function

String normalizePhone(
  1. String input
)

Normalizes the input phone number by removing separators and unifying the international prefix notation (00593, 593 and +593 become +593).

A leading 00 is only treated as an international prefix when the Ecuador country code follows it, so a local number is never mistaken for one.

input Raw phone number to normalize.

Implementation

String normalizePhone(String input) {
  String value = stripPhoneSeparators(input);
  if (value.startsWith('00$_ecDialCode')) value = '+${value.substring(2)}';
  if (value.startsWith(_ecDialCode)) value = '+$value';

  /// Remove leading zeros after the country code
  if (value.startsWith('${ecCountryCode}0')) {
    value = '$ecCountryCode${value.substring(ecCountryCode.length + 1)}';
  }

  return value;
}