checkValidPhoneNumber static method

bool checkValidPhoneNumber(
  1. String phoneNumber, {
  2. int minLength = 10,
  3. int maxLength = 15,
})

Check if string is a valid phone number

phoneNumber - The phone number to validate minLength - Minimum length (default: 10) maxLength - Maximum length (default: 15) Returns true if phone number is valid

Implementation

static bool checkValidPhoneNumber(String phoneNumber, {int minLength = 10, int maxLength = 15}) {
  // Remove all non-digit characters
  final digitsOnly = phoneNumber.replaceAll(RegExp(r'[^\d]'), '');
  return digitsOnly.length >= minLength && digitsOnly.length <= maxLength;
}