digits static method
Validates whether the given input
contains only digits.
The input
parameter should be a string representing a number.
The decimal
parameter allows decimal numbers.
The whole
parameter allows only whole numbers.
The fractions
parameter allows fraction numbers.
Returns true
if the input
matches the pattern, false
otherwise.
Implementation
static bool digits(String input,
{bool decimal = false, bool whole = false, bool fractions = false}) {
String pattern;
if (whole) {
pattern = r'^\d+$';
} else if (decimal) {
pattern = r'^\d*\.\d+$';
} else if (fractions) {
pattern = r'[-]?[0-9]+[,.]?[0-9]*([\/][0-9]+[,.]?[0-9]*)*';
} else {
pattern = r'^\d*(\.\d+)?$';
}
return RegExp(pattern).hasMatch(input);
}