+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

Adding validations to fields in the Sitefinity Form builder

by Grigori Karanikolov

The Forms module is one of the new great features we introduced in Sitefinity 4. You can use it to robustly build various user interaction forms, polls, questionnaires and more with the intuitive Sitefinity drag-and-drop interface.

Today we’ll explore the option to add validation to the text boxes, which are possibly the mostly used elements in every form. Let’s first create our form and add some widgets to it:

image

Now, if we would like to make sure that our visitors fill out the text boxes, there is a tick we can select in the text box’s designer window, which would make any of these fields are required:

image

So far, so good! However, what if we would like to make sure that the fields are filled out with content with a specific format? For example Text, Number or e-mail address? That’s absolutely possible and easy too! We need to go into the Advanced options of the textbox widget first:

image

and then proceed down to ValidatorDefinition:
image

Here we can fill out the field ExpectedFormat with the formatting the visitor is supposed to follow:

image

The different formatting options are listed in the offline Sitefinity documentation, that's available with the SDK. For ease of access, I've enclosed them below:

Value Purpose
None none by default
AlphaNumeric Validates alpha numerics
Currency Validates currency
EmailAddress Validates email addresses
Integer Validates integers
InternetUrl Validates internet urls
NonAlphaNumeric Validates non aplhanumerics
Numeric Validates numerics
Percentage Validates percentages
USSocialSecurityNumber Validates US social security numbers
USZipCode Validates US zip codes
Custom Validates against custom regular expression
GetRelatedItem Gets the item (live, temp or master) which is related with the specified item by lifecycle status. The method supports only items of type Content and ILifecycleDataItem
SetUIStatus Sets the UI status of a content object depending on whether this object also implements ILifecycleDataItemGeneric
GetUIStatus Gets the UI status of a content object depending on whether this object also implements ILifecycleDataItemGeneric
GetLanguageVersion Gets the language version.
GetUIStatusRaw
GetLanguageVersionRaw Gets the language version for the specified culture.
GetWrapperValue Gets the wrapper value.
GetPropertyValue Gets the property value.
CopyPropertiesFrom Copies all the properties of the "from" object to this object if they exist.
CopyPropertiesFrom Copies all the properties of the "from" object to this object if they exist.
CopyPropertiesTo Copies all the properties of this object to the "to" object
CopyPropertiesTo Copies all the properties of this object to the "to" object
GetSerializationPropertyValueCollection
GetListSerializationItemsItems



For example, if we would like our visitors to put an e-mail address in the text box we are configuring, we need to put EmailAddress in the ExpectedFormat field. We can also specify an error message if an invalid e-mail format is supplied:
image

And that’s that – validation is already in place! Let’s test the result:

image

9 comments

Leave a comment
  1. Patrik Feb 15, 2012
    Unfortunately, the link to the formatting options is broken...
    http://www.sitefinity.com/40/help/error.aspx?aspxerrorpath=/40/help/developers-guide/p_telerik_sitefinity_web_ui_validation_contracts_ivalidatordefinition_expectedformat.html
  2. trevor Feb 17, 2012
    an updated link would be great
  3. Grisha 'Greg' Karanikolov Apr 11, 2012
    Thanks for the feedback for the broken link, guys! We changed the way our documentation works, so for ease of access I just attached the list of validation definitions in the body of the blog post.
  4. Jeremy Nov 20, 2015
    How do code a custom validator definition when making a custom form in c#?
  5. Jeremy Nov 26, 2015
    What is the regular expression for emails that Sitefinity uses?
  6. Beth Mar 11, 2016
    The email verification doesn't work for new extended domain names such as .photography 
  7. Chris Jul 11, 2016
    Worked for me thanks!
  8. Ben Oct 11, 2016
    Does this work with Sitefinity 9. I cannot get it to work
  9. Grisha 'Greg' Karanikolov Oct 17, 2016

    Ben, are you going with the Web Forms widgets or MVC?

    Leave a comment