Validate Slug

Check if a string is a valid URL slug (lowercase, hyphen-separated).

Code

Utilities
/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug);

Parameters

Slug to validate.

Browser·fetch() may be limited by CORS

More JavaScript Snippets