Validating U.S. Bank Routing Numbers

Validating U.S. Bank Routing Numbers

In the U.S., banks use routing numbers to ensure checks and electronic transactions go to the correct institution. Each number is 9 digits in length with the 9th being a check digit. The algorithm to validate a routing number is

(3(d1?+?d4?+?d7) + 7(d2?+?d5?+?d8) + (d3?+?d6?+?d9)) mod 10 = 0        

This essentially means we multiply each digit by its weight, sum the result, and verify that the modulo 10 result is zero, where modulo 10 is the remainder after dividing a number by 10.

MS Excel

We can represent the weight assigned to the digits as 371371371. Using pseudocode the MS Excel formula becomes

=MOD(SUMPRODUCT(individual_digits_in_weight, individual_digits_in_routing_number), 10)=0        

With the routing number in cell B3, the formula is

=LET(_rtn,B3,_weight,371371371,
? ? _seq,SEQUENCE(LEN(_weight)),
? ? IF(LEN(_weight)<>LEN(_rtn),NA(),
? ? ? ? MOD(SUMPRODUCT(--MID(_weight,_seq,1),--MID(_rtn,_seq,1)),10))=0)        

or as a lambda:

=LAMBDA(_rtn,
? ? LET(_weight,371371371,_seq,SEQUENCE(LEN(_weight)),
? ? ? ? IF(LEN(_weight)<>LEN(_rtn),NA(),
? ? ? ? ? ? MOD(SUMPRODUCT(--MID(_weight,_seq,1),--MID(_rtn,_seq,1)),10))=0))        
No alt text provided for this image

Python

The Python solution is structurally similar

def isValidRoutingNumber(routingNumber):
? ? weight='371371371'
? ? return((sum([int(x)*int(y) for (x,y) in zip(routingNumber,weight)]) % 10)==0)
isValidRoutingNumber('111000025')        

For more on routing numbers see ABA routing transit number - Wikipedia

要查看或添加评论,请登录

Tushar Mehta的更多文章

  • MS Excel: How to develop a recursive function

    MS Excel: How to develop a recursive function

    Introduction A recursive function returns a value that depends on the value that the function returns for another set…

    2 条评论
  • Phone Number Region Lookup

    Phone Number Region Lookup

    Introduction We call people using phone numbers without giving much thought to what the number represents. Each number…

    1 条评论
  • MS Excel - Graph a Spill Range

    MS Excel - Graph a Spill Range

    Introduction to Dynamic Array Formulas and Spill Ranges Microsoft implemented a major improvement in Excel with the…

  • List and count unique values (MS Excel, Python, and SQL)

    List and count unique values (MS Excel, Python, and SQL)

    This is a fairly common requirement that until recently had a convoluted solution in Excel. Given a list of values, how…

    1 条评论
  • Excel Large Number Arithmetic with Python

    Excel Large Number Arithmetic with Python

    Introduction When it comes to numbers, MS Excel follows the IEEE 754 standard (Floating-point arithmetic may give…

  • MS Excel: Recursive functions

    MS Excel: Recursive functions

    In MS Excel: Functions are first-class objects, we saw how a custom Excel function, using LAMBDA, can call another…

    3 条评论
  • MS Excel: Functions are first-class objects

    MS Excel: Functions are first-class objects

    What makes a function a first-class object? This is almost certainly an advanced discussion. And, we will start with a…

  • Generate unique random integers

    Generate unique random integers

    Generating unique random integers is an important task in various domains. Examples include data sampling, simulations,…

    2 条评论
  • MS Excel: Goal Seek or Algebra

    MS Excel: Goal Seek or Algebra

    Let's start with a question. I want to pay a business through a payment processor such as PayPal.

    1 条评论
  • Calendar for the New Year

    Calendar for the New Year

    For the New Year..

    1 条评论

社区洞察

其他会员也浏览了