Skip to content

Instantly share code, notes, and snippets.

@LSTANCZYK
Forked from morsdyce/example16.cs
Created September 25, 2017 01:31
Show Gist options
  • Save LSTANCZYK/a0293dc0a99d4054fc2296eff324751f to your computer and use it in GitHub Desktop.
Save LSTANCZYK/a0293dc0a99d4054fc2296eff324751f to your computer and use it in GitHub Desktop.
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)
{
}
public override string FormatErrorMessage(string name)
{
return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString,
name, _minCharacters);
}
public override bool IsValid(object value)
{
string valueAsString = value as string;
return (valueAsString != null && valueAsString.Length >= _minCharacters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment