LSTANCZYK
9/25/2017 - 12:49 AM

Custom validation attribute to ensure a checkbox is checked

Custom validation attribute to ensure a checkbox is checked

/// <summary>
    /// This is used on mostly checkboxes that ensure that they are ticked such as terms and conditions.
    /// </summary>
    public class MustBeTrueAttribute : ValidationAttribute
    {
        public override bool IsValid(object value)
        {
            if (value == null) return false;
            if (value.GetType() != typeof(bool)) return false;

            return (bool)value;
        }
    }