Information accuracy and consistency is crucial to successful content on a website. By setting up simple field validation rules on Kentico Page Types, you can help ensure that text fields are a certain length, email addresses are formatted correctly, and number fields are within a certain range. Editors will have a much easier time with content entry if they are warned when a field is filled out incorrectly. It is important to manually review your pages before publishing, but field validation can at least give you extra confidence that your content is not breaking any rules.
Field Validation Setup
To set up basic field validation in Kentico, follow these steps:
1. Navigate to the Page Types application in Kentico
2. Click the Edit icon next to the page you want to change
3. Click Fields in the left sidebar
4. Click the field you would like to add validation to
Note: If the field is inherited from another page type, you will need to change to the page type that is mentioned in order to edit it
5. Scroll down to the Validation section on the field’s properties
6. Click
Add validation rule
7. In the box that appears, select the validation method from the first drop-down. (For this example, I selected
Email which will check for a valid email address)
8. Fill out the other available fields
9. Click Apply
10. After clicking Apply, the validation rule will be displayed in a gray box
11. If you don’t need to add any additional validation, click
Save in the upper-left to save your field
12. If additional validation is needed, click
Add validation rule again.
(For the second example, I selected Regular expression to check that all email addresses are from a specific site (test.com))
13. After adding all desired field validation, apply the validation methods and save your field
Testing Field Validation
With our new field validation in place, it’s time to test it!
1. Navigate to the Pages application in Kentico
2. Create a new page or select an existing page in the page tree on the left.
(Make sure the page is the same Page Type that we edited earlier)
3. Find your field on the Form or Content tab
4. Enter an invalid value to test the validation
5. Save the page
6. If your field validation was set up correctly, you should see the validation error appear
7. If you have additional field validation set up, test that as well
8. Save the page again
9. Finally, set your field to the correct value
10. Save the page again to make sure it saves correctly
Wrapping Up
The examples above are just the tip of the iceberg when it comes to field validation in Kentico Page Types. Using the standard Kentico validation methods, you can check the length of content, compare the value of your field to other fields, make sure phone numbers are formatted correctly, and much more. If you are interested in more advanced field validation, regular expressions and custom conditions expand the realm of possibilities even further.
Content entry on websites can be a very tedious task at times and content editors are bound to make mistakes sooner or later. Some of those mistakes can be prevented automatically with simple field validation, so why not give it a shot? Do you use Kentico field validation in your job? What are your favorite validation methods to use? Please leave a comment below and let us know!