Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
Sanity slug validate chars are lowercase

I am building a vue website using sanity as a backend. Instead of rewriting URLS in the router I want to have a pattern in place in sanity where slugs must only be lowercase letters so,

this-is-a-slug-123 would be valid but THIS-is-A-slug-123 would not be valid, I want to do this check as part of the slug validation to stop people being able to save pages with invalid slugs.

Sanity only has the required or custom validation rules available for the type slug. How can I validate the slug is solely using lowercase chars?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could incorporate a custom validation function that checks against a regex:

validation: (Rule) => Rule.required().custom((slug) => {
  if (typeof slug === "undefined") return true
  const regex = /(^[a-z0-9-]+$)/ // Regex pattern goes here
  if (regex.test(slug.current)) {
    return true
  } else {
    return "Invalid slug: Only numbers, lowercase letters, and dashes are permitted." // Error message goes here
  }
}),

This would only validate slugs containing lowercase letters, dashes, and numbers. The regex could be elaborated to account for double dashes, etc., but hopefully this is a start.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!