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?
Something to the effect of:
[0-9]{n}
where n
is the length of the bank number? Is this what you're looking for?
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.
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