Ramco Ramco

Ramco Ramco

  • 469
  • 2.8k
  • 388.4k

Field Validation

Jun 25 2021 2:05 AM

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)