checkPhoneInput function
Checks a Pakistani mobile number while the user is typing. The 03XX
prefix is checked as soon as it is complete.
checkPhoneInput('0300 12'); // InputState.incomplete
checkPhoneInput('0360'); // InputState.invalid (not allocated)
checkPhoneInput('03001234567'); // InputState.valid
Implementation
InputState checkPhoneInput(String value) {
if (toAsciiDigits(value).replaceAll(_separators, '').isEmpty) {
return InputState.empty;
}
final split = _splitPhone(value);
if (split == null) return InputState.invalid;
if (split.incomplete) return InputState.incomplete;
final national = split.national;
if (national.isEmpty) return InputState.incomplete;
if (!national.startsWith('3')) return InputState.invalid;
if (national.length >= 3 &&
!isAllocatedPrefix('0${national.substring(0, 3)}')) {
return InputState.invalid;
}
if (national.length < 10) return InputState.incomplete;
return national.length == 10 ? InputState.valid : InputState.invalid;
}