validateLocalPhone function

String validateLocalPhone(
  1. String phoneNumber
)

Validates a local Ecuadorian phone number, either mobile (10 digits starting with 09) or landline (9 digits starting with 02 to 07).

phoneNumber Phone number to validate.

Implementation

String validateLocalPhone(String phoneNumber) {
  final value = stripPhoneSeparators(phoneNumber);
  if (value.isEmpty) {
    throw PhoneException(
      PhoneErrorCode.invalidEmpty,
      EcMessageKey.phoneEmpty,
    );
  }

  if (value.length != 10 && value.length != 9) {
    throw PhoneException(
      PhoneErrorCode.invalidLength,
      EcMessageKey.phoneLocalLength,
    );
  }

  if (!_mobilePhoneRegExp.hasMatch(value) &&
      !_landlinePhoneRegExp.hasMatch(value)) {
    throw PhoneException(
      PhoneErrorCode.invalidFormat,
      EcMessageKey.phoneLocalFormat,
    );
  }

  return value;
}