Regular expression for bank account number?

I need to write a regular expression to check the valid bank account format of the main banks in the USA and Canada (I already know the format of the transit number and institution number, but I do not know the format of the account number) Does anyone know what the regular expression check is? Maybe I'll just check that all characters are numbers?

+6
regex
source share
3 answers

The USA does not comply with IBAN standards for account numbers; AFAIK is not the final US standard for account numbers, just for routing numbers.

+5
source share

I believe that phoebus is correct - there is simply no guaranteed compliance with the standards in the case of the United States, so regular expression is not as useful as you might imagine.

Account numbers corresponding to ACH (Automated Clearing House) can have up to 17 alphanumeric characters - not all financial transactions are a problem - this is ACH. (See also united-states-banking-institution-account-number-regular-expression )

In accordance with this patent document :

In field 5, located at positions 13-39, the DFI account number entails 17 characters, which example shows that it allows you to use any alphanumeric form.

Page 25 of the Guidelines of the California Tax Board for Franchising EFT is consistent with the above.

So, to at least verify ACH format compliance, check from 1 to 17 alpha numbers :

^\w{1,17}$ 

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

+2
source share

There is no American standard for bank account numbers. However, NACHA provides an ACH transaction specification that provides an example of a DFI Account Number field:

The leftmost 17 characters are inserted into the account number of the DFI field, and the remaining characters are truncated .... If less than 17 characters, left align and leave 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 with which I came. It does not match the full ASCII range, but I think that it will handle most account numbers. (17 characters consisting of a word, -., Alphanumeric with spaces if a barcode is present, not a serial, not an end)

 ^(?<DFIAccountNumber>(?=[\w\- ]{17})[0-9A-Za-z](\-?\w+)*[ ]*) 
+1
source share

All Articles