hexColorValidator static method

String? hexColorValidator(
  1. String? value, [
  2. String? errorMessage
])

hexColorValidator to validate HEX color

validator: (value) => SimpleValidations.hexColorValidator(value, [errorMessage]),

Implementation

static String? hexColorValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.hexColorRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid hexadecimal color code';
  }
  return null;
}