validatePhoneNumber function

String? validatePhoneNumber(
  1. String? phoneNumber
)

Implementation

String? validatePhoneNumber(String? phoneNumber) {
  if (phoneNumber == null || phoneNumber.isEmpty) {
    return "lbl_phone_number_required";
  } else if (!phoneNumber.contains(RegExp(r'^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$'))) {
    return "lbl_phone_number_must_be_numeric";
  } else if (phoneNumber.length < 10) {
    return "lbl_phone_number_must_be_at_least_10_digits";
  }
  return null;
}