This file contains 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 sealed class PropertiesMustMatchAttribute : ValidationAttribute | |
{ | |
private const string _defaultErrorMessage = "'{0}' and '{1}' do not match."; | |
private readonly object _typeId = new object(); | |
public PropertiesMustMatchAttribute(string originalProperty, string confirmProperty) | |
: base(_defaultErrorMessage) | |
{ | |
OriginalProperty = originalProperty; | |
ConfirmProperty = confirmProperty; |
This file contains 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
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | |
public sealed class NotEqualToAttribute : ValidationAttribute | |
{ | |
private const string DefaultErrorMessage = "{0} cannot be the same as {1}."; | |
public string OtherProperty { get; private set; } | |
public NotEqualToAttribute(string otherProperty) | |
: base(DefaultErrorMessage) | |
{ |
This file contains 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
/// <summary> | |
/// Limit numbers of items in ContentArea | |
/// Add [MaxItemCount(2)] to a prop-definition limits number of items; | |
/// [Display(Name = "Articles")] | |
/// [MaxItemCount(2)] | |
/// public virtual ContentArea ArticlesContentArea { get; set; } | |
/// </summary> | |
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | |
public sealed class MaxItemCount : ValidationAttribute | |
{ |
This file contains 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
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)] | |
public class AtLeastOneTrueAttribute : ValidationAttribute | |
{ | |
private readonly string _targetProperty; | |
public AtLeastOneTrueAttribute(string targetProperty) | |
{ | |
_targetProperty = targetProperty; | |
} |
This file contains 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
using System; | |
using System.ComponentModel.DataAnnotations; | |
using System.Linq; | |
sealed public class UsStateTwoCharacterAbbreviationAttribute : ValidationAttribute | |
{ | |
private readonly string[] validStateAbbr = new string[] { "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY" }; |
This file contains 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 sealed class ValidatePasswordLengthAttribute : ValidationAttribute | |
{ | |
private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long."; | |
private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength; | |
public ValidatePasswordLengthAttribute() | |
: base(_defaultErrorMessage) | |
{ | |
} | |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.ComponentModel.DataAnnotations; | |
using System.Text.RegularExpressions; | |
namespace MvcMovie.Service.AppService | |
{ | |
public class ImageType : ValidationAttribute |
This file contains 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
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] | |
public class RequireNonDefaultAttribute : ValidationAttribute | |
{ | |
public RequireNonDefaultAttribute() | |
: base("The {0} field requires a non-default value.") | |
{ | |
} | |
/// <summary> | |
/// Override of <see cref="ValidationAttribute.IsValid(object)"/> |
This file contains 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
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | |
public class AllowedFileExtensionsAttribute : ValidationAttribute | |
{ | |
private List<string> AllowedExtensions { get; set; } | |
public AllowedFileExtensionsAttribute(string fileExtensions) | |
{ | |
AllowedExtensions = fileExtensions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); | |
} |
This file contains 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
namespace App.Infrastructure | |
{ | |
public class FileMaxSizeAttribute : ValidationAttribute | |
{ | |
public FileMaxSizeAttribute(int maxSize = 10 * 1024 * 1024, string errorMessage = "{0} is not a valid file.") | |
: base(errorMessage) | |
{ | |
// 10 MB by default // | |
this._maxSize = maxSize; | |
} |