.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Validations >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Checking Digit Rounting Number for ABA input field In asp

Posted By:ananta       Posted Date: April 09, 2012    Points: 40    Category: Validations    URL: http://www.dotnetspark.com  

Checking Digit Rounting Number for ABA input field In asp
 

 
 public bool check_Digit_Routing_Number(string routing_Number)
    {
        bool return_Value = false;

        if (routing_Number.Length != 9)
            return return_Value;

        // 1st, 4th, 7th digits multiplied by 3
        int i_first = (int)Encoding.ASCII.GetBytes(routing_Number)[0] - 48; // 1st
        int i_fourth = (int)Encoding.ASCII.GetBytes(routing_Number)[3] - 48; // 4th
        int i_seventh = (int)Encoding.ASCII.GetBytes(routing_Number)[6] - 48; // 7th
        i_first *= 3; 
        i_fourth *= 3; 
        i_seventh *= 3;

        // 2nd, 5th, 8th digits are multiplied by 7
        int i_second = (int)Encoding.ASCII.GetBytes(routing_Number)[1] - 48; // 2nd
        int i_fifth = (int)Encoding.ASCII.GetBytes(routing_Number)[4] - 48; // 5th
        int i_eighth = (int)Encoding.ASCII.GetBytes(routing_Number)[7] - 48; // 8th
        i_second *= 7; 
        i_fifth *= 7;
        i_eighth *= 7;

        // 3rd, 6th muliplied by 1
        int i_third = (int)Encoding.ASCII.GetBytes(routing_Number)[2] - 48; // 3rd
        int i_sixth = (int)Encoding.ASCII.GetBytes(routing_Number)[5] - 48; // 6th
        i_third *= 1;
        i_sixth *= 1;

        // sum products
        int i_sum_products = i_first + i_second + i_third + i_fourth + i_fifth + i_sixth + i_seventh + i_eighth;

        // subtract sum from next higher mulitple of 10
        int i_next_multiple_ten = ((i_sum_products / 10) + 1) * 10;

        int i_ninth = (int)Encoding.ASCII.GetBytes(routing_Number)[8] - 48;

        int i_check_sum = i_next_multiple_ten - i_sum_products;

        // only one digit
        if (i_check_sum == 10)
            i_check_sum = 0;

        //int i_check_sum = (i_sum_products + i_ninth) % 10;
        // result is check digit
        // compare against 9th digit
        return_Value = (i_check_sum == i_ninth);
        return return_Value;
    }


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend