Open cdekkers opened 4 years ago
PR welcome.
On a related note, the current expression does not allow for slugs with 1 to 2 characters. The proposed one does.
That this library even wants to validate a slug; it is overreaching it's initial domain; validation of known quantities.
A slug can be implemented differently per cms/site and one may not match another. The case in hand €test
is a valid slug, and should always be a valid slug. It may not be a compatible with your cms slug; but it is valid.
@cdekkers Create a separate issue for related note problem.
https://github.com/validatorjs/validator.js/blob/bab507ad4a33156ece15582268b2fe0ab3bbca1d/src/lib/isSlug.js#L3
This regex does not invalidate slugs that start with a special character. For example,
€test
is allowed as a slug. Perhaps this one is a better solution:/^[a-z0-9]+(?:(?:-|_)+[a-z0-9]+)*$/
More info and tests: https://regexr.com/5eqe6