slugValidator static method

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

slugValidator to validate slug

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

Implementation

static String? slugValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.slugRegex;

  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid slug';
  }
  return null;
}