日期:2014-05-16  浏览次数:20468 次

多种信用卡的js验证
<script src="js/WebUIValidation.js" type="text/javascript"></script>
    <Script LANGUAGE="JavaScript" type="text/javascript">
    <!-- Begin
    var Cards = new makeArray(8);
    Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16");
    var MasterCard = Cards[0];
    Cards[1] = new CardType("VisaCard", "4", "13,16");
    var VisaCard = Cards[1];
    Cards[2] = new CardType("AmExCard", "34,37", "15");
    var AmExCard = Cards[2];
    Cards[3] = new CardType("DinersClubCard", "30,36,38", "14");
    var DinersClubCard = Cards[3];
    Cards[4] = new CardType("DiscoverCard", "6011", "16");
    var DiscoverCard = Cards[4];
    Cards[5] = new CardType("enRouteCard", "2014,2149", "15");
    var enRouteCard = Cards[5];
    Cards[6] = new CardType("JCBCard", "3088,3096,3112,3158,3337,3528", "16");
    var JCBCard = Cards[6];
    var LuhnCheckSum = Cards[7] = new CardType();

    /*************************************************************************\
    CheckCardNumber(form)
    function called when users click the "check" button.
    \*************************************************************************/
    function CheckCardNumber(form) {
    var tmpyear;
    //if (form.CardNumber.value.length == 0) {
    //alert("Please enter the CardNumber");
   // form.CardNumber.focus();
    //return false;
    //}
    if(form.ExpMon.value.length==0)
    {
     alert("Please enter the Expiration Month");
     form.ExpMon.focus();
     return false;
    }
    if(form.ExpMon.value<1|| form.ExpMon.value>12)
    {
      alert("The Expiration Month is not valid.");
      return false;
    }
    if (form.ExpYear.value.length == 0)
    {
        alert("Please enter the Expiration Year.");
        form.ExpYear.focus();
        return false;
    }
    if (form.ExpYear.value > 96)
    tmpyear = "19" + form.ExpYear.value;
    else if (form.ExpYear.value < 21)
    tmpyear = "20" + form.ExpYear.value;
    else
    {
    alert("The Expiration Year is not valid.");
    return false;
    }
   
    tmpmonth = form.ExpMon.value;
    // The following line doesn't work in IE3, you need to change it
    // to something like "(new CardType())...".
    // if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {
    if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) {
    alert("This card has already expired.");
    return false;
    }
    card = form.CardType.options[form.CardType.selectedIndex].value;
    var retval = eval(card + ".checkCardNumber(\"" + form.CardNumber.value +
    "\", " + t