isDigitsOnly method

bool isDigitsOnly()

Checks if the entire string consists only of numerical digits (0-9).

@returns True if the string contains one or more digits and no other characters (including spaces).

Example:

print('12345'.isDigitsOnly());   // true
print('123 a'.isDigitsOnly());   // false

Implementation

bool isDigitsOnly() => RegExp(r'^\d+$').hasMatch(this);