Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Required]
- [MinimumAge(18, ErrorMessage = "must be 18 years old or up")]
- [Display(Name = "Birth date")]
- public DateTime birthdate { get; set; }
- public class MinimumAgeAttribute : ValidationAttribute
- {
- int _minimumAge;
- public MinimumAgeAttribute(int minimumAge)
- {
- _minimumAge = minimumAge;
- }
- public override bool IsValid(object value)
- {
- DateTime date;
- if (DateTime.TryParse(value.ToString(), out date))
- {
- return date.AddYears(_minimumAge) < DateTime.Now;
- }
- return false;
- }
- }
- if (DateTime.TryParse(value.ToString(), out date))
Add Comment
Please, Sign In to add comment