'.Net Core=I want add personality rules for UserValidator
For Example; I have password column in the table. AnyBody while enter system must write password. I want contain password minumum one character such as(/,-,?,+,!). I did such one code;
public UserValidator()
{
RuleFor(p => p.Password).MinimumLength(10);
RuleFor(p => p.Password).Must(MustBeCharacter);
}
private bool MustBeCharacter(string arg)
{
return arg.Contains("."+","+"?"+"!"+"*"+"-"+"+");
}
I take a problem. system want all of them ("."+","+"?"+"!"+"*"+"-"+"+"). but I want minimum one more. How can I do this rule. Thank you so much
Solution 1:[1]
System want all of them because you are looking for entire string and not one character.
you need array first
private string[] arr = [".",",","?","!","*","-","+"];
private bool MustBeCharacter(string arg)
{
return arr.Any(s => args.Contains(s));
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dotnetstep |
