validate method

  1. @override
bool validate(
  1. dynamic value, [
  2. List<String>? options
])
override

Validates whether the given value is a valid slug.

A valid slug contains only lowercase letters, numbers, and hyphens.

value - The value to be validated. It can be of any type. options - An optional list of additional options for validation.

Returns true if the value is a valid slug, otherwise false.

Implementation

@override
bool validate(dynamic value, [List<String>? options]) {
  if (value == null) return false;
  return RegExp(r'^[a-z0-9]+(?:-[a-z0-9]+)*$').hasMatch(value.toString());
}