コード例 #1
0
 public static PremiseValidator TextIsCreditCardNumber <S>(this PremiseValidator context) where S : IResponseMessage, new()
 {
     return(context.Must <S>(value =>
     {
         int sum = 0;
         int mul = 1;
         int count = (value as string).Count();
         for (int i = 0; i < count; i++)
         {
             var digit = (value as string).Substring(count - i - 1, count - i);
             var product = int.Parse(digit) * mul;
             sum += (product >= 10) ? ((product % 10) + 1) : (product);
             if (mul == 1)
             {
                 mul++;
             }
             else
             {
                 mul--;
             }
         }
         if ((sum % 10) == 0)
         {
             return (true);
         }
         else
         {
             return (false);
         }
     }));
 }
コード例 #2
0
        public static PremiseValidator TextIsWithin <S>(this PremiseValidator context, int lower, int upper = 99999999) where S : IResponseMessage, new()
        {
            return(context.Must <S>(value =>
            {
                var count = (value as string).Count();

                return count >= lower && count <= upper;
            }));
        }
コード例 #3
0
 public static PremiseValidator TextIsAlphaNumeric <S>(this PremiseValidator context) where S : IResponseMessage, new()
 {
     return(context.Must <S>(value => value != null ? (value as string).Replace(" ", "").All(char.IsLetterOrDigit) : false));
 }
コード例 #4
0
 public static PremiseValidator TextIsNumeric <S>(this PremiseValidator context) where S : IResponseMessage, new()
 {
     return(context.Must <S>(value => value == null || (value as string).All(char.IsNumber)));
 }
コード例 #5
0
 public static PremiseValidator TextIsNotEmpty <S>(this PremiseValidator context) where S : IResponseMessage, new()
 {
     return(context.Must <S>(value => !string.IsNullOrWhiteSpace(value as string)));
 }
コード例 #6
0
 public static PremiseValidator DateIsInPast <S>(this PremiseValidator context) where S : IResponseMessage, new()
 {
     return(context.Must <S>(value => (value as DateTime?) < DateTime.Now));
 }