pctValidator static method

String? pctValidator(
  1. String? doubleString
)

pctValidator returns null if the given doubleString is a valid percentage.

Implementation

static String? pctValidator(String? doubleString) {
  if (doubleString == null || doubleString.isEmpty) {
    return ("Cannot be empty");
  }
  if (!RegExp(r'^[0-9]+.?[0-9]*$').hasMatch(doubleString) &&
      (doubleString).isNotEmpty) {
    return ("Only a positive number <= 100 is allowed");
  }
  if (double.tryParse(doubleString)! > 100) {
    return ("Only a positive number <= 100 is allowed");
  }
  return (null);
}