Skip to content

Commit

Permalink
Optimize regex validator (#2035)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccallum committed Jan 11, 2023
1 parent f97553a commit 514d853
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public class RegularExpressionValidator<T> : PropertyValidator<T,string>, IRegul
}

public override bool IsValid(ValidationContext<T> context, string value) {
if (value == null) {
return true;
}

var regex = _regexFunc(context.InstanceToValidate);

if (regex != null && value != null && !regex.IsMatch(value)) {
if (regex != null && !regex.IsMatch(value)) {
context.MessageFormatter.AppendArgument("RegularExpression", regex.ToString());
return false;
}
Expand Down

0 comments on commit 514d853

Please sign in to comment.