Mailto scheme not working in Sanity URI validation
I can see why you're experiencing issues with mailto: validation! This is actually a known quirk with how Sanity's URL field type works in the browser.
The good news is your validation rule is correctly configured:
validation: (Rule) => Rule.required().uri({scheme: ['http', 'https', 'tel', 'mailto']})What's happening:
When you use type: 'url' in Sanity, it renders as an HTML <input type="url"> element. The browser's native HTML5 validation for URL input fields doesn't recognize mailto: or tel: as valid URL formats, even though they're perfectly valid URI schemes. This creates a conflict where Sanity's validation passes, but the browser blocks the form submission with its own validation error.
The solution:
Change your field type from url to string while keeping your validation rule exactly as is:
{
name: 'link',
title: 'Link',
type: 'string', // Changed from 'url'
validation: (Rule) => Rule.required().uri({
scheme: ['http', 'https', 'tel', 'mailto']
})
}This approach:
- Bypasses the browser's native URL validation that's causing the conflict
- Still enforces proper URI format through Sanity's
Rule.uri()validation - Works perfectly for all URI schemes including
mailto:andtel: - Provides the same Studio experience (just without the browser's overly-strict validation)
The url field type is essentially a string field with some UI conveniences and browser-level validation. By using string with Rule.uri(), you get all the validation you need without the browser interference. The field will still validate that your users enter properly formatted URIs with the schemes you've specified - it just won't fight with the browser about what constitutes a "valid URL."
Show original thread4 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.