django / django-localflavor

Country-specific Django helpers, formerly of contrib fame
https://django-localflavor.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
828 stars 290 forks source link

BICValidator: Validate location code #418

Closed raphaelm closed 4 years ago

raphaelm commented 4 years ago

We are still seing some (syntactically) invalid BICs in the wild. These are an annoyance, since banks and banking software validates BICs against the official standards and if we allow BICs that aren't allowed by the standard, we'll run into problems even loading the files in banking software.

The official regex in use in the XML schemas is [A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}. Currently, we do restrict to the same regex, except for the disallowance of 1 at position 7 and O at position 8. This PR adds these restrictions.

Sources

All Changes

benkonrath commented 4 years ago

Looks good, thanks!

I think it's probably worth switching to a validator that uses the official regex. I didn't know about this when I wrote it. The disadvantage to the regex is that it's an all or nothing validation - it will only report valid or invalid but that's probably good enough for most use cases.

In any case, let's get this in now and I'll replace it at some point in the future if / when I have some spare time.