Skip to content

Instantly share code, notes, and snippets.

@dejanvasic85
Created February 29, 2016 00:35
Show Gist options
  • Save dejanvasic85/117e0953bd74a1dd5be7 to your computer and use it in GitHub Desktop.
Save dejanvasic85/117e0953bd74a1dd5be7 to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment