✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Products

By Abu Taher Muhammad

Ecommerce: Product schema

product.js

{
  name: 'product',
  title: 'Product'
  fields: {
    name: 'email',
    title: 'Email',
    type: 'string',
    validation: Rule => Rule.custom(email => {
        if (typeof email === 'undefined') {
            return true // Allow undefined values
        }
        
        return email.toLowerCase()
            .match(
                /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
              )
              
            ? true
            : 'This is not an email'
      })
  }
}

Contributor