[Required]
[ValidatePasswordLength]
[DataType(DataType.Password)]
[Display(Name = "Password")]
[Minimumthreenumbers]
public string Password { get; set; }
public class MinimumthreenumbersAttribute : ValidationAttribute
{
private const string _defaultErrorMessage = "There should be minimum three letters in the string";
private string Otherpassword;
public MinimumthreenumbersAttribute() : base(_defaultErrorMessage)
{
}
public override bool IsValid(object value)
{
string i = value.ToString();
string jobId = i;
int digitsCount = 0;
foreach (char c in jobId)
{
if (Char.IsDigit(c))
digitsCount++;
}
if (digitsCount > 3)
{
return true;
}
else
{
return false;
}
}
}
The above is the custom attribute implementation class .The above code actually has to validate the password to check for minimum 3 numbers.If the user entered password has less than 3 digits it should throw an error.This is the requirement. But is not working as expected. Any ideas on how to make the above code working? I have tried for some time but still it is not working.