This blog will show you how to setup your Textboxes on a Sitefinity form with input validation. If you've been working with previous versions of Sitefinithy the first question you may have is "wait a minute, Sitefinity has built-in forms?". Yes, Sitefinity 4.0 includes a new Form Builder, which allows you to create form modules that can be shared in multiple pages of your website. They are very simple to setup and once you have created a form, you just drop a form control on a page and point it to your form. In addition, Sitefinity will automatically persist the input data in your Sitefinity database in a table Sitefinity creates specifically for your new form. For more information on Sitefinity 4.0 forms, take a look at an excellent Blog written by Gabe Sumner at Sitefinity.
Now, getting back to our original problem. Let's imagine you have dropped a Textbox form widget on your form in which you only want to accept integer values. The Sitefinity team thought of this situation and designed a solution to help you out. The reason for this blog is to point in the proper direction, because it a little difficult to figure out which property to use and what values you should enter.
The way to get Sitefinity to validate a user's input data is to "Edit" your textbox widget.
click the "Advanced" button in the TextBox property editor dialog:
In the advanced view of the TextBox property editor, scroll down until the "ValidatorDefinition" button comes into view and click that:
Then find the "ExpectedFormat" input box and type in "Integer". (In addition, you can easily create your own custom error message in the "IntegerValidationMessage" property which is shown to your users if the "ExpectedFormat" is not correct.)
Here's an example showing the error message:
If you are looking for input validation other than integer, the possible values you can enter into the "ExpectedFormat" property are from the ValidationFormat Enumeration.
If you've read this far, hopefully documenting these steps will save you some time plugging in input validation on your Sitefinity 4.0 forms.