For what its worth, none of these answers are very clear. What you are trying to do is set a minimum and maximum length attribute essentially. There are basically a few ways you can accomplish this using data annotations.
The easiest way:
[MinLength(7)]
[MaxLength(7)]
Using StringLengthAttribute... StringLength has two overloaded methods. Both have the int parameter @maximumLength
and one of the overloads includes NamedParameters. So for maxlength you wouldn't use a named parameter but for minlength you would:
[StringLength(7, MinimumLength=7)]
If you want to be really confusing you could also do it this way:
[MinLength(7)]
[StringLength(7)]