API Reference: RegularExpressionAttribute Class

This attribute is part of the .NET System.ComponentModel.DataAnnotations namespace.

The RegularExpressionAttribute can be applied to string-based content model properties. The attribute sets a regular expression pattern against which the property value will be validated. The back office will display a validation error if the property value is not a match for the specified regular expression.


Decorate the model property with the RegularExpressionAttribute. Pass the regular expression pattern in the attribute constructor.


public class SampleContent: IContentType
    // Sets a regular expression to validate a RFC 1123 hostname
    public string Hostname { get; set; }

    // ...