Simple Field Validation for Page Types in Kentico 12

By Tyler Pfohl On January 17, 2020

Simple Field Validation for Page Types in Kentico 12
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
Explanation of where the Edit icon is located on the Page Types application

3. Click Fields in the left sidebar
Explanation of where Fields option is on 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
Example of a selecting a field

5. Scroll down to the Validation section on the field’s properties

6. Click Add validation rule
Explanation of where the "Add Validation Rule" is

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
Examples of validation rule fields

10. After clicking Apply, the validation rule will be displayed in a gray box
Example of validation rule displaying 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))
Example of adding additional validation

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
    Example of entering 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
Example of validation error

7. If you have additional field validation set up, test that as well
Example of additional field validation set up test

8. Save the page again


9. Finally, set your field to the correct value
Example of setting correct value

10. Save the page again to make sure it saves correctly
Example of "saved" notification

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!

Share This Post:

Twitter Pinterest Facebook Google+
Click here to read more Kentico posts
Start a Project with Us
Photo of the author, Tyler Pfohl

About the author

Tyler originates from the corn-filled land of Iowa and has loved technology since he was little. Originally he wanted to become a programmer but his older brother introduced him to the amazing world of QA in 2014. Ever since then, he has developed a hunger for ensuring high quality. His latest passion is using automation to quickly find issues on web pages. When he’s not making his computer work for him, you can usually find him playing video games, riding his bike, or trying a new craft beer.

View other posts by Tyler

Subscribe to Updates

Stay up to date on what BizStream is doing and keep in the loop on the latest with Kentico.