ASP.Net Mvc Fixed-Length String Data Annotation

Varan Sinayee picture Varan Sinayee · Apr 21, 2016 · Viewed 11k times · Source

How can I set the string validation for a fixed-length string using data annotation ?

I want to have a property on my model with the exact 10 string-length.

I'm counting the seconds for help.

Answer

Max picture Max · Apr 21, 2016

1) [StringLength(10, MinimumLength = 10)]

2) [RegularExpression(@"(.{10})")]