Skip to content

Instantly share code, notes, and snippets.

@LSTANCZYK
LSTANCZYK / NotAllowedHtml.cs
Created September 25, 2017 01:54 — forked from csharpforevermore/NotAllowedHtml.cs
NotAllowedHtml.cs is a data annotation addi
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;
using System.Xml.Linq;
namespace CommonFunctions.Validation
{
@LSTANCZYK
LSTANCZYK / DateGreaterThanAttribute.cs
Created September 25, 2017 01:54 — forked from elizabeth-young/DateGreaterThanAttribute.cs
Validation attribute for testing a data is later than another
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class DateGreaterThanAttribute : ValidationAttribute, IClientValidatable
{
private const string DefaultErrorMessageFormatString = "The {0} field is required.";
public string OtherProperty { get; private set; }
public DateGreaterThanAttribute(string otherProperty)
{
if (string.IsNullOrEmpty(otherProperty))
{
@LSTANCZYK
LSTANCZYK / AtLeastOneAttribute.cs
Created September 25, 2017 01:54 — forked from christopherbauer/AtLeastOneAttribute.cs
AtLeastOne Attribute and Validator Implementation for MVC 3+ (Note: only validates client-side)
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class AtLeastOneAttribute : ValidationAttribute, IClientValidatable
{
public string GroupName { get; private set; }
public AtLeastOneAttribute(string groupName)
{
GroupName = groupName;
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
@LSTANCZYK
LSTANCZYK / NotBeforeAttribute.cs
Created September 25, 2017 01:35 — forked from vanillajonathan/NotBeforeAttribute.cs
Ensures that the end date is not prior to the start date.
using System;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Reflection;
namespace DataAnnotations
{
/// <summary>
/// Provides an attribute that compares two properties of a model and
class ObservableDataPropertyAttribute : Attribute
{
}
class DependsOnAttribute : Attribute
{
public string Dependency { get; private set; }
public DependsOnAttribute(string dependency)
{
@LSTANCZYK
LSTANCZYK / MinDigitsIncluded.cs
Created September 25, 2017 01:34 — forked from elizabeth-young/MinDigitsIncluded.cs
Validation attribute for ensuring a minimum number of digits entered
public class MinDigitsIncluded : ValidationAttribute, IClientValidatable
{
private const string DefaultErrorMessage = "{0} must contain at least {1} digits.";
public int MinDigits { get; private set; }
public MinDigitsIncluded(int minDigits) : base(DefaultErrorMessage)
{
MinDigits = minDigits;
}
@LSTANCZYK
LSTANCZYK / ByteInfoAttribute.cs
Created September 25, 2017 01:34 — forked from linuxbender/ByteInfoAttribute.cs
EF 4.2 - MVC 3 - File Validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace demo_002.Models
{
public class ByteInfoAttribute : ValidationAttribute
{
using System.ComponentModel.DataAnnotations;
using System.Web;
using Orchard;
using Patient.Framework.AntiSpam.Services;
namespace Patient.Framework.AntiSpam.Attributes {
public class RecaptchaAttribute : ValidationAttribute {
public sealed class CollectionMinimumLengthAttribute : ValidationAttribute
{
private const string ErrorMessageWithMax = "{0} must contain between {1} and {2} item(s).";
private readonly int _minLength;
public CollectionMinimumLengthAttribute(int min)
{
_minLength = min;
MaxLength = null;
public class MaxWords : ValidationAttribute
{
private int _maxWords;
public MaxWords(int maxWords)
: base("{0} has too many words")
{
_maxWords = maxWords;
}