Enforce/validate URL field to start with '/'

  • 2 September 2022
  • 1 reply

Userlevel 1

When you start entering a new string into the URL field of a content type, it defaults to leading with a forwards slash. However, a content editor can remove this and still publish the content (ie “/about” vs “about”). The problem that I have found is that on a NextJS site using SSR the context.resolvedUrl object in getServerSideProps will always return a leading forwards slash. When we query the API with this value, it won’t grab any entries which have had the forwards slash removed by a content editor. 


Outside of custom field validation, is there any way around this?


Best answer by bethany.wiles 2 September 2022, 23:01

View original

1 reply

Userlevel 1

Hi Will, 

Rather than building out a custom field, I’d go with a single line textbox field and use the advanced settings to configure a Regex validation that checks for the /. You can see more in the docs on that here: Should be quicker than building a custom field. Let me know if that works for you.