πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Validation of url input to allow certain URI schemes

By Saskia Bobinska

Validation of url input to allow certain URI schemes (mailto, tel and more included)

url schema with uri validation

{
      name: 'url',
      title: 'Url',
      type: 'url',
      description: `Can be a path starting with a '/' or a full Url starting with 'http://' or 'https://'`,
      validation: (Rule) =>
        Rule.uri({
          allowRelative: true,
          scheme: ['http', 'https', 'mailto', 'tel'],
        }),
    },

Sometimes we want to make sure, users can add links for tel: and mailto: too.
To make sure these URI schemes are allowed and won't result in warnings and errors, you can add this validation to your url schema field and make sure, the urls are right, no matter what they open!

Contributor

Other schemas by author