API Reference: MinLengthAttribute Class

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

The MinLengthAttribute can be applied to string-based content model properties. The attribute sets the minimum required character length of a string property value. The back office will display a validation error if the property value length is less than the specified minimum. If the property type is a collection (f.e. IList<string>), every value in the collection is validated individually.

You can combine this attribute with the MaxLength attribute to specify a min/max length range.

Usage

Decorate the model property with the MinLengthAttribute. Pass the minimum required length in the attribute constructor.

Example

The following example sets a minimum length of 10 characters for the Title property (as well as a maximum length of 50).

public class SampleContent: IContentType
{
    [MinLength(10)]
    [MaxLength(50)]
    public string Title { get; set; }

    // ...
}