PhoneNumber constructor
PhoneNumber(
- String? str
Returns a valid PhoneNumber object.
Throws ValueException:
- RequiredValueException if
str
is null or empty. - InvalidValueException if
str
is not a valid phone number.
Implementation
factory PhoneNumber(String? str) {
if (str == null || str.isEmpty) {
throw const RequiredValueException();
}
if (validate(str)) {
return PhoneNumber._(str);
}
throw InvalidValueException(str, message: 'Invalid phone number.');
}