validatePhone method

bool validatePhone()

Validates whether the string is a valid phone number.

This method checks if the phone number consists of 8 to 13 numeric digits. It does not allow special characters, spaces, or country codes.

Returns:

  • true if the phone number contains only digits (8 to 13 characters long).
  • false otherwise.

Example Usage:

String phone1 = "9876543210";
bool isValid1 = phone1.validatePhone(); // true

String phone2 = "12345";
bool isValid2 = phone2.validatePhone(); // false (too short)

String phone3 = "+919876543210";
bool isValid3 = phone3.validatePhone(); // false (contains country code)

Implementation

bool validatePhone() => hasMatch(this, r'(^[0-9]{8,13}$)');