validMobileNumber static method

Map<String, dynamic>? validMobileNumber(
  1. AbstractControl control
)

Implementation

static Map<String, dynamic>? validMobileNumber(
  AbstractControl<dynamic> control,
) {
  if (control.value == null || control.value.toString().isEmpty) {
    return null;
  }

  const pattern = r'^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$';

  if (RegExp(pattern).hasMatch(control.value.toString())) return null;

  if (control.value.toString().length < 10) return {'mobileNumber': true};

  return {'mobileNumber': true};
}