开发者

Regular Expression for Bank Account Number?

开发者 https://www.devze.com 2022-12-12 13:35 出处:网络
I need to write a regular expression to check for valid bank acc开发者_如何学编程ount number format of major banks in USA and Canada (I already know the format for transit number and institution numbe

I need to write a regular expression to check for valid bank acc开发者_如何学编程ount 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?


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


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+)*[ ]*)
0

精彩评论

暂无评论...
验证码 换一张
取 消