Credit card number Verification

Source: Internet
Author: User

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;  --'ll be indicator for every and other number int firstnumtoadd = 0; --'ll be used to store sum of first set of numbers int secondnumtoadd = 0;            --'ll be used to store second set of numbers string num1;             --would be used if every and other number added is greater than, store the left-most integers here string num2;            --'ll be used if ever Yother number added are greater than, 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 is on the odd number of numbers, Add. Number to OU                    R total Firstnumtoadd + = Ccadd;                --Set our indicator to 0 so, our code would know to skip to the next piece indicator = 0;                    } else {//--If the current integer doubled is greater than 10 --Split the sum in to, integers and add them together//--we then add it to O  ur total here if ((Ccadd + ccadd) >=) {int temporary =                        (Ccadd + ccadd); NUM1 = temporary. ToString ().                        Substring (0,1); num2 = temporary. ToString (). Substring ();                    Secondnumtoadd + = (Convert.ToInt32 (NUM1) + Convert.ToInt32 (num2)); } else {//--Otherwise, just add them together and add them                    To We total secondnumtoadd + = Ccadd + Ccadd;                    }//--set our indicator to 1 so for the next integer we'll perform a different set of code                indicator = 1; }}//--If the sum of our 2 numbers are divisible by ten, then the card is valid.            Otherwise, it is not bool IsValid = false;            if ((Firstnumtoadd + secondnumtoadd)% = = 0) {IsValid = true;            } else {isValid = false;        } return isValid; }///<summary>//Get and check to make sure, the chosen credit card type matches the// /Card number//</summary>//<param name= "Ccnum" >string</param>//&LT;RETURNS&GT;BOOL&L            T;/returns> public bool Retrievecctype (string ccnum, int intchosentype) {//return value            BOOL Bresult = false;                 if (Convert.ToInt32 (ccnum.substring (0,2)) >= Wuyi && Convert.ToInt32 (ccnum.substring (0,2)) <= 55) {                 Check to see which 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)) = = "PNs") {//American Express//Check to See that the card matches the type they chose if (Intchosentype = = 1) {b                Result = true;                } else {bresult = false; }} else if (Convert.ToString (ccnum.substring (0,4)) = = "6011") {//Discove                R card if (Intchosentype = = 2) {bresult = true;                } else {bresult = false;            }} else {bresult = false;        } return bresult; }    }}

  

Credit card number Verification

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.