The Sandbox https://www.drupal.org/sandbox/encelado/1936168 uses the PHP-IBAN library. Which is quite extensive.

My patch is a proposal for a short but valid version.

CommentFileSizeAuthor
#2 iban_validator-2329137-1.patch1.68 KBrudiedirkx
#1 iban_validator-2329137-1.patch1.69 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

rudiedirkx’s picture

Status: Active » Needs review
FileSize
1.68 KB

Patch in #1 is bad. Wrong regex and wrong match check.

Attached patch is good: allow up to 14 numbers.

TR’s picture

Status: Needs review » Needs work

The regexp is just plain wrong. You use

'/^[a-z]{2}\d{2}[a-z]{4}\d{8,14}$/i'

Problems are:

  1. [a-z]{4} is just wrong - there is no requirement that the BBAN start with 4 characters. The format of the BBAN is totally country specific, and may be up to 30 alphanumeric characters in any order. For example, Sweden is entirely numeric with no characters at all.
  2. [a-z]{4}\d{8,14} implies a BBAN of between 12 and 18 digits. Again, that's just wrong. A BBAN is allowed to be up to 30 characters so in theory you should be checking for a BBAN between 1 and 30 digits. Although in practice the shortest is Norway at 11 characters (which would be disallowed by your regexp) and the longest is Saint Lucia at 28 characters (also disallowed by your regexp).
  3. You neglect to strip whitespace, which in practice is almost always entered.

If you plan to add something like this, it is almost mandatory that you provide test cases so that the proper functioning can be assured. Regardless, if you're going to do it, please take the time and do the research to get it correct. As it stands, it rejects valid IBAN numbers and allows invalid IBAN numbers, so in some ways it's worse than no validation at all.

rudiedirkx’s picture

That's simple then. Don't add it.

We only tried Dutch IBAN, so there was no extensive research. I guess a regex that will validate for all countries is impossible.