×

Loading...
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!

I have a function to check the credit card number is valid or not. But I have some other questions.

本文发表在 rolia.net 枫下论坛My questions:
1. How to realize the transaction through Internet.
2. As I know, some small company use a third company(for example: Wordpay ) to do the payment online. Do you guys know how it works?
3. As a small company , can I get the money directly from Visa, Master or etc.
I am a beginner and blind in this area, so ask all the experts for help.


function isValidCardNumber(strNum)
{
var nCheck = 0;
var nDigit = 0;
var bEven = false;
var dLength = 0;
var checkOk = false;

strNum = strNum.replace(/ /g,"");

dLength = strNum.length;

if (strNum.substring(0,1) == '4')
{
if (dLength == 13 || dLength == 16)
checkOk = true;
else
return false;
}
else if (strNum.substring(0,2) == '34' || strNum.substring(0,2) == '37')
{
if (dLength == 15)
checkOk = true;
else
return false;
}
else if (strNum.substring(0,2) == '51' || strNum.substring(0,2) == '52'
|| strNum.substring(0,2) == '53' || strNum.substring(0,2) == '54'
|| strNum.substring(0,2) == '55')
{
if (dLength == 16)
checkOk = true;
else
return false;
}
else
return false;


for (n = strNum.length - 1; n >= 0; n--)
{
var cDigit = strNum.charAt (n);
if (isDigit (cDigit))
{
var nDigit = parseInt(cDigit, 10);
if (bEven)
{
if ((nDigit *= 2) > 9)
nDigit -= 9;
}
nCheck += nDigit;
bEven = ! bEven;
}
else if (cDigit != ' ' && cDigit != '.' && cDigit != '-')
{
return false;
}
}
return (nCheck % 10) == 0;
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT杂谈 / 请问大家谁写过on-line信用卡信息试别(试别name, number,...)的use Script . 如何证明用户输入的信息是否数实?
    • web knows ==>
      • thank you, I will try
    • 俺用perl写过,就是把所有的属性,当作相应变量提交过去一个request,然后等收到一个response,根据返回值判断是否成功。
      • thank you
    • 只是检查号码是否符合生成规则,并不保证号码有效。
      • 请问 How to 保证号码有效? I saw some shopping cart package having this functional (not very sure)
        • 保证有效得去VISA查吧,自己肯定无法判断的
    • 可以用JavaScript在客户端实现,一般算法是这样,
      首先验证信用卡的位数和第一个数字或前两个数字是否有效,比如说VISA卡长度为13或16,第一个数字必须为4;MasterCard卡长度为16,前两个数字位于51-55之间;然后在按照用户输入的信用卡号码依照算法将位数进行处理,最后看能否被10整除,如果能整除,则验证通过,否则号码无效。
    • I have a function to check the credit card number is valid or not. But I have some other questions.
      本文发表在 rolia.net 枫下论坛My questions:
      1. How to realize the transaction through Internet.
      2. As I know, some small company use a third company(for example: Wordpay ) to do the payment online. Do you guys know how it works?
      3. As a small company , can I get the money directly from Visa, Master or etc.
      I am a beginner and blind in this area, so ask all the experts for help.


      function isValidCardNumber(strNum)
      {
      var nCheck = 0;
      var nDigit = 0;
      var bEven = false;
      var dLength = 0;
      var checkOk = false;

      strNum = strNum.replace(/ /g,"");

      dLength = strNum.length;

      if (strNum.substring(0,1) == '4')
      {
      if (dLength == 13 || dLength == 16)
      checkOk = true;
      else
      return false;
      }
      else if (strNum.substring(0,2) == '34' || strNum.substring(0,2) == '37')
      {
      if (dLength == 15)
      checkOk = true;
      else
      return false;
      }
      else if (strNum.substring(0,2) == '51' || strNum.substring(0,2) == '52'
      || strNum.substring(0,2) == '53' || strNum.substring(0,2) == '54'
      || strNum.substring(0,2) == '55')
      {
      if (dLength == 16)
      checkOk = true;
      else
      return false;
      }
      else
      return false;


      for (n = strNum.length - 1; n >= 0; n--)
      {
      var cDigit = strNum.charAt (n);
      if (isDigit (cDigit))
      {
      var nDigit = parseInt(cDigit, 10);
      if (bEven)
      {
      if ((nDigit *= 2) > 9)
      nDigit -= 9;
      }
      nCheck += nDigit;
      bEven = ! bEven;
      }
      else if (cDigit != ' ' && cDigit != '.' && cDigit != '-')
      {
      return false;
      }
      }
      return (nCheck % 10) == 0;
      }更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • see the c# code
      public bool Validate(string cardNumber, DateTime expDate)
      {
      if(expDate >= DateTime.Today)
      {
      int total = 0;
      int temp = 0;
      char [] ccDigits = cardNumber.ToCharArray();
      for(int i = 0; i < cardNumber.Length; i++)
      {
      if(((i+1)%2) == 0)
      {
      total += int.Parse(ccDigits[i].ToString());
      }
      else
      {
      temp = int.Parse(ccDigits[i].ToString()) * 2;
      if(temp > 9)
      {
      temp = (int)temp - 9;
      }
      total += temp;
      }
      }
      if((total%10) ==0)
      {
      return true;
      }
      else
      {
      return false;
      }
      }
      else
      {
      return false;
      }
      }