Slug
Validate URL slugs — lowercase letters, digits, and hyphens.
Validates that a value is a URL slug: lowercase letters, digits, and hyphens, with no leading or trailing hyphen.
| Config flag | Type | Description |
|---|
slug | boolean | When true, requires the value to be a valid slug. |
const form = useForm({
initialValues: { slug: '' },
validationSchema: {
slug: { slug: true },
},
});
import { V } from 'formify-js';
V.slug();
| Scenario | Message |
|---|
| Value is not a valid slug | Must be a valid slug |
| Value | Result |
|---|
'my-blog-post' | ✅ Valid |
'post-2024' | ✅ Valid |
'My-Blog' | ❌ Invalid (uppercase) |
'-post' | ❌ Invalid (leading hyphen) |
- Only lowercase
a-z, digits, and internal hyphens are accepted — underscores and uppercase letters fail.
- If your content system auto-generates slugs, use this validator as a safety check before submit.