checkValidIndianMobileNumber static method

bool checkValidIndianMobileNumber(
  1. String mobileNumber
)

Check if string is a valid Indian mobile number

mobileNumber - The mobile number to validate Returns true if mobile number is valid

Implementation

static bool checkValidIndianMobileNumber(String mobileNumber) {
  // Remove all non-digit characters
  final digitsOnly = mobileNumber.replaceAll(RegExp(r'[^\d]'), '');

  // Check if it's 10 digits and starts with 6, 7, 8, or 9
  if (digitsOnly.length == 10) {
    return RegExp(r'^[6-9]').hasMatch(digitsOnly);
  }

  // Check if it's 12 digits with country code 91
  if (digitsOnly.length == 12) {
    return digitsOnly.startsWith('91') && RegExp(r'^91[6-9]').hasMatch(digitsOnly);
  }

  return false;
}