ASP.Net Mvc Fixed-Length String Data Annotation
12,045
Solution 1
1) [StringLength(10, MinimumLength = 10)]
2) [RegularExpression(@"(.{10})")]
Solution 2
Try
[StringLength(10, MinimumLength = 10, ErrorMessage = "This field must be 10 characters")]
public string myString {get;set;}
Author by
Varan Sinayee
I started programming based on MS technologies when I was 16 at vocational school, and I am currently working as a freelancer about 6 years.
Updated on July 04, 2022Comments
-
Varan Sinayee almost 2 years
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.
-
Fatih Çakıroğlu about 2 yearsEF CORE has AddFixedLength() method => same action