Verify the implementation code of the bank card number in JavaScript, and verify the javascript code

Source: Internet
Author: User

Verify the implementation code of the bank card number in JavaScript, and verify the javascript code

1. Introduce jquery. js first

2. Introduce luhmCheck. js // Luhm verification of the bank card number.

3. See the following case:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Below is the js

<Script type = "text/javascript"> function CheckBankNo (t_bankno) {var bankno = $. trim (t_bankno.val (); if (bankno = "") {$ ("# banknoInfo" ).html ("enter the bank card number"); return false;} if (bankno. length <16 | bankno. length> 19) {$ ("# banknoInfo" ).html ("the length of the bank card number must be between 16 and 19"); return false ;} var num =/^ \ d * $/; // full number if (! Num.exe c (bankno) {$ ("# banknoInfo" ).html ("bank card numbers must all be numbers"); return false ;}// the first six digits var strBin = ", 18, 30,35, 37,40, 41,42, 43,44, 45,46, 47,48, 5E, 51,52, 53,54, 55,56, 58,60, 62,65, 68,69, 84,87, 88,94, 95,98, 99. indexOf (bankno. substring (0, 2) =-1) {$ ("# banknoInfo" ).html ("the first six digits of the bank card number do not comply with the specifications"); return false ;} // Luhm check (new) if (! LuhmCheck (bankno) return false; $ ("# banknoInfo" ).html ("verified! "); Return true ;}</script>

Test card No:

1. 6222600810010710887

2. 6225881414207430

The above is the implementation code for verifying the bank card number in JavaScript introduced by xiaobian. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

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.