5
Answers

Field Validation

Ramco Ramco

Ramco Ramco

3y
465
1

Hi

  I have written below Annotation on a field . If it is required in another in will have to write it again

. Can we create only once thru class each Annotation separately or some other way so that it can be used in any class


        [DataType(DataType.Text)]
        [Required(ErrorMessage = "Description can not be blank.")]
        [StringLength(25, ErrorMessage = "Max length should be less than or equal to 25.")]
        [RegularExpression(@"^[a-zA-Z][a-zA-Z ]+$", ErrorMessage = "Special Characters not allowed")]
        [Display(Name = "Description")]

Thanks

Answers (5)