Skip to content

Add Swedish Bankgiro number validation#506

Open
cedendahlkim wants to merge 1 commit into
arthurdejong:masterfrom
cedendahlkim:feat/swedish-bankgiro
Open

Add Swedish Bankgiro number validation#506
cedendahlkim wants to merge 1 commit into
arthurdejong:masterfrom
cedendahlkim:feat/swedish-bankgiro

Conversation

@cedendahlkim

Copy link
Copy Markdown

Summary

Add stdnum.se.bankgiro module for validating Swedish Bankgiro numbers.

Bankgiro numbers are used in Sweden to identify bank giro accounts for invoice payments and transfers. They consist of 7 or 8 digits with a Luhn (mod-10) check digit — the same algorithm already used by stdnum.se.orgnr and stdnum.se.personnummer.

Changes

  • New module: stdnum/se/bankgiro.py — implements validate(), is_valid(), compact(), format()
  • New tests: tests/test_se_bankgiro.doctest — covers valid/invalid numbers, formatting, edge cases

Design

Follows the established patterns from stdnum.se.orgnr:

  • Uses stdnum.luhn.validate() for the mod-10 check
  • Accepts both 7-digit (NNN-NNNN) and 8-digit (NNNN-NNNN) formats
  • The format() function hyphenates at position 3 or 4 depending on length

Testing

>>> from stdnum.se.bankgiro import validate, is_valid, format
>>> validate('9000001')
'9000001'
>>> validate('50501501')
'50501501'
>>> is_valid('9000002')
False
>>> format('9000001')
'900-0001'

References

Add stdnum.se.bankgiro module for validating Swedish Bankgiro
numbers (7-8 digits with Luhn/mod-10 check digit).

Includes:
- validate, is_valid, compact, format functions
- Doctests in module and dedicated test file
- Follows existing patterns from stdnum.se.orgnr

Refs: https://www.bankgirot.se/en/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant