标签:成功 ext 用例 card false git pac code 验证
1 /// <summary> 2 /// Is valid? 3 /// </summary> 4 /// <param name="context">Validation context</param> 5 /// <returns>Result</returns> 6 protected override bool IsValid(PropertyValidatorContext context) 7 { 8 var ccValue = context.PropertyValue as string; 9 if (string.IsNullOrWhiteSpace(ccValue)) 10 return false; 11 12 ccValue = ccValue.Replace(" ", ""); 13 ccValue = ccValue.Replace("-", ""); 14 15 var checksum = 0; 16 var evenDigit = false; 17 18 //http://www.beachnet.com/~hstiles/cardtype.html 19 foreach (var digit in ccValue.Reverse()) 20 { 21 if (!char.IsDigit(digit)) 22 return false; 23 24 var digitValue = (digit - ‘0‘) * (evenDigit ? 2 : 1); 25 evenDigit = !evenDigit; 26 27 while (digitValue > 0) 28 { 29 checksum += digitValue % 10; 30 digitValue /= 10; 31 } 32 } 33 34 return (checksum % 10) == 0; 35 }
358973017867754 失败
标签:成功 ext 用例 card false git pac code 验证
原文地址:https://www.cnblogs.com/micro-chen/p/11557928.html