使用Jquery进行信用卡验证 [英] Credit Card validation with Jquery

查看:171
本文介绍了使用Jquery进行信用卡验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery验证信用卡号,但我不想使用验证插件,是否还有其他插件可以执行此操作?

I'm trying to validate credit card numbers with jQuery but i dont want to use the validation plugin , is there any other plugin for doing this?

推荐答案

http://en.wikipedia .org/wiki/Luhn_algorithm

您可以在下面将其最小化为很小的代码.

You could minimize this below into a very small footprint in your code.

function isCreditCard( CC )
 {                        
      if (CC.length > 19)
           return (false);

      sum = 0; mul = 1; l = CC.length;
      for (i = 0; i < l; i++)
      {
           digit = CC.substring(l-i-1,l-i);
           tproduct = parseInt(digit ,10)*mul;
           if (tproduct >= 10)
                sum += (tproduct % 10) + 1;
           else
                sum += tproduct;
           if (mul == 1)
                mul++;
           else
                mul--;
      }
      if ((sum % 10) == 0)
           return (true);
      else
           return (false);
 }

这篇关于使用Jquery进行信用卡验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆