Created
August 5, 2022 18:05
-
-
Save flpinheiro/de28c53d103ca00c24393746a4b9fbb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [AttributeUsage(AttributeTargets.Property)] | |
| public class DateLimitValidationAttribute : RequiredAttribute | |
| { | |
| protected override ValidationResult IsValid(object value, ValidationContext validationContext) | |
| { | |
| base.IsValid(value, validationContext); | |
| if (value == null) return ValidationResult.Success; | |
| var date = Convert.ToDateTime(value); | |
| var ageOfDateInDays = DateTime.Today.Subtract(date).Days; | |
| if (ageOfDateInDays > 90) | |
| { | |
| return new ValidationResult("Select Date can not be older than 90 days, or 3 months."); | |
| } | |
| else | |
| { | |
| return ValidationResult.Success; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment