Validating SWIFT/BIC codes: the rules, a regex and an API

A SWIFT or BIC code is 8 or 11 characters: 4 letters for the bank, a 2-letter ISO country code, 2 letters or digits for the location and an optional 3-character branch. A regex plus a country-code check catches most typos, but only SWIFT's paid directory can prove a code exists. Our SWIFT / BIC Check API validates the format, splits the parts and names the bank when GLEIF's open BIC-to-LEI data knows it, for $0.002 per call.

Try it free SWIFT BIC Check API — format, country, branch, $0.002 · $0.002 / call

The parts of a BIC

These rules come from ISO 9362. An 8-character BIC means the same as the 11-character form ending in XXX.

CharactersPartExample (DEUTDEFFXXX)Rule
1-4InstitutionDEUTLetters only
5-6CountryDEAn ISO 3166 country code
7-8LocationFFLetters or digits; a 0 in position 8 marks a test BIC
9-11Branch (optional)XXXXXX is the head office; other codes starting with X are not used

A regex for the format

The regex accepts "ABCDZZ22", because ZZ fits two letters. Keep a list of ISO country codes and check characters 5-6 against it.

import re

BIC = re.compile(r"^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$")

def looks_like_bic(s):
    s = s.replace(" ", "").upper()
    return bool(BIC.match(s))  # still check the country code separately

What no free check can tell you

A well-formed BIC can still belong to no bank. The official BIC directory (SWIFTRef) is a paid product, so free tools, ours included, can't confirm every code. Our API adds one open source on top of the format check: GLEIF publishes which BICs map to which LEIs under CC0. When the code is in that file you get the bank's legal name, LEI, country and city; when it isn't, the answer says so instead of guessing. Large banks are usually in it; many smaller ones aren't.

Calling the API

Codes with the wrong length or characters are refused and not charged. Spaces and dashes are removed before the check, so copy-pasted codes work.

curl -i -X POST https://iamai.markets/api/x402/services/4omwQWJV3Ewe \
  -H "Content-Type: application/json" \
  -d '{"bic": "DEUTDEFFXXX"}'

# result: valid_format, problems[], institution_code, country_code, location_code,
# branch_code, test_bic, passive_participant, bic11, registry_match

The product

Questions

Is a SWIFT code the same as a BIC?

Yes. BIC is the formal name in ISO 9362; people call it a SWIFT code because SWIFT registers them.

Should I use the 8 or 11 character form?

Either, unless the bank asks for a branch. Our API returns both forms.

Can this replace IBAN validation?

No. IBANs have their own check digits and format per country; validate them separately.

Related

Updated 2026-12-02