Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression for Bank Account Number?

Tags:

regex

I need to write a regular expression to check for valid bank account number format of major banks in USA and Canada (I already know the format for transit number and institution number, but I don't know the format for account number). Does anyone know what regular expression check should be? Perhaps I just check to make sure all characters are digits?

like image 431
John Avatar asked Nov 24 '09 01:11

John


3 Answers

The US doesn't conform to IBAN standards for account numbers; AFAIK there is no definitive US standard for account numbers, just for routing numbers.

like image 162
phoebus Avatar answered Oct 20 '22 07:10

phoebus


I believe phoebus is correct - there's simply no guaranteed standards compliance in the case of the USA, so a regex isn't as helpful as one might imagine.

Account numbers complying with the ACH (Automated Clearing House) network standard can have up to 17 alphanumeric characters - the problem is not all financial transactions are ACH. (SEE also united-states-banking-institution-account-number-regular-expression)

According to this patent document:

For field 5, located at position 13-39, DFI account number entails 17 characters, which the example shows as allowing any alphanumeric form.

Page 25 of State of California Tax Francise Board EFT Program Guide agrees with the above.

 

So, to a least check ACH format compliance, check for 1 to 17 alpha-numerics:

^\w{1,17}$

 

A resource that show a specific use of the ACH standard:
http://ribbs.usps.gov/ncsc_ach_pay_instruct/documents/tech_guides/Memphis_NCSC_ACH_Credit_Payment_Option.pdf

like image 42
micahwittman Avatar answered Oct 20 '22 08:10

micahwittman


There is not a US standard for bank account numbers. However, NACHA provides a specification for ACH transactions which states for an example Account Number field (DFI Account Number):

The leftmost 17 characters are inserted in the DFI Account Number field and the remaining characters truncated. ... If fewer than 17 characters, left justify and leave the unused spaces blank.

The DFI Account Number field as part of the CCD Entry Detail is indicated as 'alphameric' (ASCII values greater than 0x1F).

Here is the regex I came up with. It doesn't match on the full ASCII range but I think it will handle most account numbers. (17 characters long composed of word,-,. alphanumeric leading. rightpad with spaces. if dash present-not consecutive and not at end)

^(?<DFIAccountNumber>(?=[\w\- ]{17})[0-9A-Za-z](\-?\w+)*[ ]*)
like image 27
Jay Walker Avatar answered Oct 20 '22 06:10

Jay Walker