Computer Magic Logo

Wednesday, March 16, 2016

Published by Aristotelis Pitaridis

The CMUmbracoToolsRegularExpression attribute works the same way like the RegularExpressionAttribute in ASP.NET MVC. It takes two parameters. The first parameter defines the regular expression which will be used in order to validate the value typed by the user. The second parameter defines the name of the dictionary which contains the error message that the system will display if the user types an invalid value.

[CMUmbracoToolsRegularExpression(@"^[A-Z]{2}$", "Country Code field can only be two alphabetic characters in capital.")]
public string CountryCode { get; set; }

In order to use the CMUmbracoToolsDisplay attribute we have to define the following using.

using CMUmbracoTools.DataAnnotations;