Skip to content

Instantly share code, notes, and snippets.

@DaveHogan
Last active September 25, 2017 00:08
Show Gist options
  • Select an option

  • Save DaveHogan/6556124 to your computer and use it in GitHub Desktop.

Select an option

Save DaveHogan/6556124 to your computer and use it in GitHub Desktop.
MVC ValidationAttribute to ensure property is empty. Sounds strange but I create for an anti-bot field to which is hidden in css but bots still try filling in.
public class MustBeEmptyAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null)
{
return true;
}
if (value is string)
{
if (((string) value).Length == 0)
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment