相关疑难解决方法(0)

CreditCardAttribute使用哪种算法进行信用卡号格式验证

.NET 4.5包含一个名为as的新验证属性CreditCardAttribute,该属性指定数据字段值是信用卡号.当我反编译包含此类的程序集时,我可以看到以下代码用于信用卡号验证:

public override bool IsValid(object value)
{
  if (value == null)
  {
    return true;
  }
  string text = value as string;
  if (text == null)
  {
    return false;
  }
  text = text.Replace("-", "");
  text = text.Replace(" ", "");
  int num = 0;
  bool flag = false;
  foreach (char current in text.Reverse<char>())
  {
    if (current < '0' || current > '9')
    {
      return false;
    }
    int i = (int)((current - '0') * (flag ? '\u0002' : '\u0001'));
    flag …
Run Code Online (Sandbox Code Playgroud)

.net c# algorithm validation credit-card

4
推荐指数
1
解决办法
3187
查看次数

标签 统计

.net ×1

algorithm ×1

c# ×1

credit-card ×1

validation ×1