コード例 #1
0
        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)));
        }
コード例 #2
0
 public static StringValidator DigitsOnly() =>
 v => Optional(v)
 .Filter(x => x.ForAll(char.IsDigit))
 .ToValidation(StringError.DigitsOnly());
コード例 #3
0
 public static StringValidator MustNotContain(string part) =>
 v => Optional(v)
 .Filter(x => !x.Contains(part))
 .ToValidation(StringError.MustNotContain(part));
コード例 #4
0
 public static StringValidator MaxLength(int length) =>
 v => Optional(v)
 .Filter(x => x.Length <= length)
 .ToValidation(StringError.MaxLength(length));