Tuesday, April 25, 2017

Validators

 [Display(Name = "Zip Code")]
        [Required(ErrorMessage = "Enter your zip code")]
        [RegularExpression(@"^\d{5}(-\d{4})?$", ErrorMessage = "Invalid zip code")]
        public string Zip { get; set; }



[RegularExpression(@"^(\d{4})$", ErrorMessage = "Invalid Social Security Number")]




----

When ModelState is invalid check for specific errors:

var errors = ModelState.Values.SelectMany(v => v.Errors);





No comments:

Post a Comment