<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0-preview.5.20278.1" />

System.ComponentModel.DataAnnotations.StringLengthAttribute

Specifies the minimum and maximum length of characters that are allowed in a data field.
public int MaximumLength { get; }

Gets or sets the maximum length of a string.

public int MinimumLength { get; set; }

Gets or sets the minimum length of a string.

public StringLengthAttribute(int maximumLength)

Initializes a new instance of the StringLengthAttribute class by using a specified maximum length.