Slug Validator
Check whether a slug is in valid format (a-z, 0-9, hyphens, no accents, no spaces, no double or edge hyphens). Suggests a fix. Everything in your browser.
Sugestão:
Slug validation: from raw title to clean URL
A slug is the URL-friendly version of a string. It strips diacritics, lowercases letters, replaces spaces with hyphens and keeps only ASCII characters that survive transparently in URLs without percent-encoding. The canonical example is the WordPress permalink: a post titled "Minha Primeira Postagem" becomes minha-primeira-postagem, not Minha%20Primeira%20Postagem. Validating a slug means checking it matches the agreed convention so that routing, SEO and downstream systems stay consistent.
Slugs are everywhere: WordPress and Ghost post URLs, Stripe customer IDs, e-commerce category and product URLs, GitHub repository names, npm package names, Kubernetes resource names. Each platform has slightly different rules, but they all converge on the same idea: predictable, readable, unambiguous identifiers that work in URLs, filenames, DNS labels and CLIs.
Strict vs permissive regex
The strict slug pattern is ^[a-z0-9]+(-[a-z0-9]+)*$: lowercase ASCII letters and digits, single hyphens as separators, never leading or trailing or doubled. The permissive pattern ^[a-z0-9_-]+$ allows underscores and is common in package managers (npm, PyPI). Use strict for public URLs and permissive for internal IDs where readability over SEO matters less.
// JavaScript
const STRICT = /^[a-z0-9]+(-[a-z0-9]+)*$/
const PERMISSIVE = /^[a-z0-9_-]+$/
STRICT.test('minha-primeira-postagem') // true
STRICT.test('Minha-Primeira') // false (uppercase)
STRICT.test('hello--world') // false (double hyphen)
Accent removal and transliteration
Slug libraries normalize Unicode to NFD then strip combining marks, so José becomes jose, Açaí becomes acai and São Paulo becomes sao-paulo. For non-Latin scripts (Cyrillic, Arabic, Chinese) the choice is between transliteration tables (Москва → moskva) and punycode for international URLs. The popular libraries slugify, slug (npm) and python-slugify bundle locale-aware tables (German ß → ss, ä → ae; French œ → oe).
Length limits and SEO
Most CMSs cap slugs at 200 characters (WordPress) but SEO best practice keeps them under 60 because Google truncates long URLs in SERPs and shorter slugs concentrate ranking signal. Some teams strip stop words (a, the, of, e, da, do) to tighten the URL; others keep them for natural language. Google parses individual words from the slug, so meaningful keywords beat GUID-only slugs like post-3f8a7e1c, which Search Console reports as poorly ranked.
Collisions, auto-generation and manual override
Most CMSs auto-generate the slug from the post title at first save and let the editor override it. On collision (two posts with the same title), the platform appends a counter (post-2, post-3) or a short hash. Rails uses friendly_id with history tables so old slugs 301-redirect to the current one — critical when a post is renamed but external backlinks already exist.
Permalink structures and platform conventions
- WordPress:
/year/month/day/slugtraditional;/category/slugor/slugmodern. - Ghost:
/slugflat; respects content/post types. - GitHub repos:
^[a-z0-9._-]+$, max 100 chars; case-insensitive but stored as written. - npm packages: lowercase, no spaces, may include
@scope/, max 214 chars. - Stripe IDs:
cus_*,sub_*— opaque slugs with type prefix.
FAQ
Should I use underscore or hyphen? Hyphen. Google explicitly treats hyphens as word separators and underscores as joiners (my_post is parsed as one word). Use hyphens for SEO URLs and reserve underscores for code identifiers.
What is the ideal slug length? Under 60 characters for SEO, under 200 to satisfy most CMSs, and reasonable enough that humans can read it in an email or chat without scrolling.
How do I handle multi-language sites? Slugify per locale: store one slug per language and route via locale prefix (/en/my-post, /pt/minha-postagem). Never reuse the English slug for translated content — it tanks local SEO.
What about emojis in slugs? Most validators reject them; even if the platform accepts, URL encoding turns them into long percent-encoded blobs. Strip emojis during slugify.
Can I change a slug after publishing? Yes, but set up a 301 redirect from the old slug to the new one. Skipping the redirect breaks backlinks and loses ranking earned by the original URL.
Related Tools
CPF Validator
Validate Brazilian CPF numbers instantly using the official algorithm. Useful for testing document validation in applications. No data sent to servers.
Batch CPF Validator
Validate a list of CPFs (one per line) and see which are valid and which are not. No data sent to servers.
Batch CNPJ Validator
Validate a list of CNPJs (one per line) with a summary of valid, invalid and total. No data sent to servers.