JavaScript Commander verification of bank card number implementation code _javascript tips

Source: Internet
Author: User

1, first introduced jquery.js

2, followed by the introduction of Luhmcheck.js//bank card number Luhm check

3, look at the following case:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
 

Here is JS

<script type= "Text/javascript" >
function Checkbankno (t_bankno) {
  var bankno = $.trim (T_bankno.val ()); c3/> if (Bankno = = "") {
    $ ("#banknoInfo"). HTML ("Please fill in the bank card number");
     return false;
   }
   if (Bankno.length < | | bankno.length >) {
     $ ("#banknoInfo"). HTML ("bank card number length must be between 16 to 19");
     return false;
   }
   var num =/^\d*$/; Full digit
   if (!num.exec (Bankno)) {
     $ ("#banknoInfo"). HTML ("bank card number must be all numbers");
     return false;
   }
   The opening 6-bit
   var strbin = " 10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99 ";
   if (Strbin.indexof (bankno.substring (0, 2)) = = 1) {
     $ ("#banknoInfo"). HTML ("the bank card number at the beginning of 6-bit does not conform to the specification");
     return false;
   }
   Luhm Checksum (new)
   if (!luhmcheck (bankno)) return
     false;
     $ ("#banknoInfo"). HTML ("Validate through!");
     return true;
   }
</script>

Test Card number:

1, 6222600810010710887

2, 6225881414207430

The above is a small set to introduce the JavaScript commander of the code to check the bank card number, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.