Insights

Sitecore Field Validation: A Guide

Sitecore Field Validation

The Sitecore field validators are a set of user-input validators that can be applied to an item, a specific field type, or a specific field on an item. All validation rules could be viewed at the sitecore path: /sitecore/system/settings/validation rules

When applying the validation rules to a particular field we need to decide on how the result of validation must be reflected in the user interface. For that purpose any of the below fields could be chosen from the Validation Rules section.

Quick Action Bar - applies validation to the left of the field

Validate Button - validation results are displayed when Validation button on the Review tab is clicked

Screenshot of the validation results in Sitecore

Validator Bar -applies validation to the bar at the right of the fields

Workflow -applies validation when workflow is running.

Suppose we need to create a new maximum length validator(like 35 characters) which is not available as part of the default field rules.

Create a duplicate of the maximum length 40 validator rule at the path /sitecore/system/Settings/Validation Rules/Field Rules/Sample

Set the title description and parameter fields accordingly.

Screenshot of the title and description fields in Sitecore's Text section

Screenshot of the parameters field in Sitecore's data section

The Result parameter determines the result of validation for that particular validator.

The query string in the parameter field of validator needs to be [parameter]=[value]&[parameter]=[value]

For example, for the maximum length of 35 characters validator the parameter value would be MaxLength=35&Result=CriticalError

Here the Result determines whether to prevent the user from saving the item or just warn the user to check the value provided in the field.

Results

Accordingly the Result parameter can have the below values:

Valid = Green, everything is fine

Suggestion = Gray, suggesting user to have a look at the value provided in the field

Screenshot of the suggested field character count in Sitecore

Warning = Orange, warning the user to do something about this particular value

Screenshot of a warning fields in Sitecore

Error = Red, this is an error but user is allowed to save

Screenshot of a field error in a Sitecore field

CriticalError = Red, user is warned before saving

Screenshot of a critical error message in Sitecore

FatalError = Red, user cannot save item before validator is cleared

Screenshot of a fatal error message in Sitecore

Note: If the Result parameter is not provided its defaulted to Error type.

Once the new maximum length validator is created and saved we need to apply the validator on the template or the field of an item. It could be applied to any of the fields in the validation section as discussed in the beginning of the blog. Choose appropriately and make sure that the validation option selected ensures rightful validation of a user input.

A useful help text could also be provided near to the field name to indicate the user the maximum characters allowed in the field too.

Always take care not to overdo validation and keep it simple so that the editing process is smooth and content is valid.

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting
 

Meet Anju Thomas

Sitecore Web Developer

🎞🥘🧩

Anju is a Sitecore Developer with a Bachelor's Degree in Computer Science and over 4 years of experience in Sitecore development. She loves solving Sudoku puzzles, watching movies, eating delicious food and exploring the world.

Connect with Anju