Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set min and max annotations on a property with Data Annotations Extensions?

How do i set the min and max annotation on a Property, with Data Annotations Extensions?

This is what i have tried:

[Required(ErrorMessage = "Dette felt er påkrævet!")]
        [Digits(ErrorMessage = "Indtast kun cifre")]
        [Min(8, ErrorMessage = "Brugernavnet skal være 8 tegn langt.")]
        [Max(8, ErrorMessage = "Brugernavnet skal være 8 tegn langt.")]
        [Display(Name = "Brugernavn")]
        public string UserName { get; set; }

I get the following error:

Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: range

like image 422
Kenci Avatar asked Dec 27 '22 09:12

Kenci


1 Answers

Min and Max are for decimal types. For strings you use the [StringLength] or the [RegularExpression] attributes:

[StringLength(8, MinimumLength = 8)]
public string UserName { get; set; }
like image 125
Darin Dimitrov Avatar answered May 21 '23 08:05

Darin Dimitrov