slugValidator static method
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;
}