public static StringValidator MatchRegex(string regexPattern) { var regex = new Regex(regexPattern, RegexOptions.Compiled); return(v => Optional(v) .Filter(x => regex.IsMatch(x)) .ToValidation(StringError.DoesNotMatchRegex(regexPattern))); }
public static StringValidator DigitsOnly() => v => Optional(v) .Filter(x => x.ForAll(char.IsDigit)) .ToValidation(StringError.DigitsOnly());
public static StringValidator MustNotContain(string part) => v => Optional(v) .Filter(x => !x.Contains(part)) .ToValidation(StringError.MustNotContain(part));
public static StringValidator MaxLength(int length) => v => Optional(v) .Filter(x => x.Length <= length) .ToValidation(StringError.MaxLength(length));