validatePhone method

String? validatePhone(
  1. String input
)

Implementation

String? validatePhone(String input) {
  const pattern = r'(^[0-9]{10}$)'; // 2345678901
  final regExp = RegExp(pattern);
  const pattern2 = r'(^\d{3}-\d{3}-\d{4}$)'; //234-567-8901
  final regExp2 = RegExp(pattern2);

  if (input.isEmpty) {
    return 'Entry Required';
  } else if (input.length > 10) {
    return 'Maximum of 10 digits';
  } else if (!(regExp.hasMatch(input) || regExp2.hasMatch(input))) {
    return 'Only numeric digits accepted';
  } else {
    return null;
  }
}