-
-
Save LSTANCZYK/41bbf8e8d12ddd07d458ff4de036a8ce 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.
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
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