信用卡号 验证

using System;

namespace CreditCards
{
    /// <summary>
    /// Summary description for CreditCardValidator.
    /// </summary>
    public class CreditCardValidator
    {
        public CreditCardValidator()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public bool ValidateCC(string creditNo)
        {
            int indicator = 1;        //-- will be indicator for every other number
            int firstNumToAdd = 0;  //-- will be used to store sum of first set of numbers
            int secondNumToAdd = 0; //-- will be used to store second set of numbers
            string num1;            //-- will be used if every other number added is greater than 10, store the left-most integer here
            string num2;            //-- will be used if ever yother number added is greater than 10, store the right-most integer here

            //-- Convert our creditNo string to a char array
            char[] ccArr = creditNo.ToCharArray();

            for (int i=ccArr.Length-1;i>=0;i--)
            {
                char ccNoAdd = ccArr[i];
                int ccAdd = Int32.Parse(ccNoAdd.ToString());
                if (indicator == 1)
                {
                    //-- If we are on the odd number of numbers, add that number to our total
                    firstNumToAdd += ccAdd;
                    //-- set our indicator to 0 so that our code will know to skip to the next piece
                    indicator = 0;
                }
                else
                {
                    //-- if the current integer doubled is greater than 10
                    //-- split the sum in to two integers and add them together
                    //-- we then add it to our total here
                    if ((ccAdd + ccAdd) >= 10)
                    {
                        int temporary = (ccAdd + ccAdd);
                        num1 = temporary.ToString().Substring(0,1);
                        num2 = temporary.ToString().Substring(1,1);
                        secondNumToAdd += (Convert.ToInt32(num1) + Convert.ToInt32(num2));
                    }
                    else
                    {
                        //-- otherwise, just add them together and add them to our total
                        secondNumToAdd += ccAdd + ccAdd;
                    }
                    //-- set our indicator to 1 so for the next integer we will perform a different set of code
                    indicator = 1;
                }
            }
            //-- If the sum of our 2 numbers is divisible by 10, then the card is valid. Otherwise, it is not
            bool isValid = false;
            if ((firstNumToAdd + secondNumToAdd) % 10 == 0)
            {
                isValid = true;
            }
            else
            {
                isValid = false;
            }
            return isValid;
        }

        /// <summary>
        /// Get and check to make sure that the chosen credit card type matches the
        /// card number
        /// </summary>
        /// <param name="CCNum">string</param>
        /// <returns>bool</returns>
        public bool RetrieveCCType(string CCNum, int intChosenType)
        {
            // return value
            bool bResult = false;

            if (Convert.ToInt32(CCNum.Substring(0,2)) >= 51 && Convert.ToInt32(CCNum.Substring(0,2)) <= 55)
            {
                // Check to see that the type of card that the user selected
                // matches the
                if(intChosenType == 3)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                }
            }
            else if (Convert.ToString(CCNum.Substring(0,1)) == "4")
            {
                // Visa

                if(intChosenType == 4)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                }
            }
            else if (Convert.ToString(CCNum.Substring(0,2)) == "34" || Convert.ToString(CCNum.Substring(0,2)) == "37")
            {
                // american express
                // check to see that the card matches the type they chose
                if(intChosenType == 1)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                }
            }
            else if(Convert.ToString(CCNum.Substring(0,4)) == "6011")
            {
                // Discover card
                if(intChosenType == 2)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                }
            }
            else
            {
                bResult = false;
            }

            return bResult;
        }
    }
}

  

时间: 2024-10-10 02:02:04

信用卡号 验证的相关文章

java实现重要信息的加密解密(模拟信用卡号的保存)

package cn.felay.io; import java.io.Externalizable; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io

Android中验证输入是否为汉字及手机号,邮箱验证,IP地址可用port号验证

1,验证是否为汉字 // 验证昵称 private boolean verifyNickname() { String nickname = edt_username.getText().toString(); if (nickname == null || nickname.length() == 0) { edt_username.setError("不能为空"); return false; } int len = 0; char[] nickchar = nickname.to

做一个牛XX的身份证号验证类(支持15位和18位)

原文:做一个牛XX的身份证号验证类(支持15位和18位) #region 是否合法的中国身份证号码 protected bool IsChineseID() { if (str.Length == 15) str = CidUpdate(str); if (str.Length == 18) { string strResult = CheckCidInfo(str); if (strResult == "非法地区" || strResult == "非法生日" |

18位身份证号验证及信息获取

止乎于分享! IDCode18 = { validate: function (value) { if (value.length != 18) return false; var value = value.toLowerCase(); var sum = 0, v = '10x98765432', w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2], a = '11,12,13,14,15,21,22,23,31,32,33,3

身份证号验证 银行卡号验证

身份证号验证 /* 审批系统的身份证验证 * 身份证15位编码规则:dddddd yymmdd xx p * dddddd:6位地区编码 * yymmdd: 出生年(两位年)月日,如:910215 * xx: 顺序编码,系统产生,无法确定 * p: 性别,奇数为男,偶数为女 * * 身份证18位编码规则:dddddd yyyymmdd xxx y * dddddd:6位地区编码 * yyyymmdd: 出生年(四位年)月日,如:19910215 * xxx:顺序编码,系统产生,无法确定,奇数为男

微信公众号验证TOKEN

服务端验证微信token header('Content-type:text'); define("TOKEN", "weixin"); $signature = $_GET['signature'];//微信待验证参数 $timestamp = $_GET['timestamp'];//时间戳 $nonce = $_GET['nonce'];//随机数 $token = TOKEN;//token 公众号后台配置的 $tmpArr = array($timesta

身份证号验证

/** * 验证输入身份证号 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b> */ public static boolean IsIDcard(String str) { String regex = "(^\\d{18}$)|(^\\d{15}$)"; return match(regex, str); }

比较规范的身份证号验证正则表达式

一些要求用户信息比较严格的地方比如用户注册.登录的时候都需要验证用户的身份证是否合法,而通过这些验证能大大的过滤掉很多水客,给你的系统带来非常精准的用户信息. 很多时候我们都是通过一组正则表达式来判断用户输入的身份证是否合法,那在用正则表达式判断之前,你对身份证号的组成有多少了解呢?下面来说说一个身份证号里面包含了多少的信息: 1.号码的结构 公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成.排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码.

POS恶意软件,可回传信用卡号及个人资料

FighterPOS的功能和其他PoS恶意软件家族相似,可以收集信用卡磁道1,磁道2和CVV码,还包含内存撷取功能,此外,攻击者可以通过键盘测录功能测录到受感染终端上的按键记录. 趋势科技发现巴西有100多家受害组织受到FighterPOS的影响,已经窃取超过22,000笔不重复的信用卡号码,其创作者似乎在支付诈骗和恶意软件制造上有很长的历史,我们认为这个恶意软件创作者是独立行动,没有任何同伙协助.FighterPOS目前售价是18比特币(约为5,250美元)虽然不便宜但精心设计的控制面板和多种