Format
Strips whitespace and uppercases, then matches `/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/`. If `countries` is set, the 2-letter prefix must be in that list. Final step is the standard IBAN mod-97 = 1 check, computed in 7-char chunks (no BigInt, edge-worker safe).
Examples
- CH93 0076 2011 6238 5295 7 (CH, 21 chars)
- DE89 3704 0044 0532 0130 00 (DE, 22 chars)
- GB82 WEST 1234 5698 7654 32 (GB, 22 chars, alpha bank code)
Implementation
Faithful summary of lib/validators.ts. Validators are pure functions and run identically in the worker, the Workbench, and the MCP server.
function validIban(value, params) {
const v = value.replace(/\s+/g, '').toUpperCase()
if (!/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(v)) return fail('iban_format', 'bad IBAN format')
const countries = Array.isArray(params.countries) ? params.countries : null
if (countries && !countries.includes(v.slice(0, 2))) {
return fail('iban_country', `country ${v.slice(0, 2)} not allowed`)
}
const rearranged = v.slice(4) + v.slice(0, 4)
const expanded = rearranged.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55))
let mod = 0
for (let i = 0; i < expanded.length; i += 7) {
mod = Number(`${mod}${expanded.slice(i, i + 7)}`) % 97
}
return mod === 1 ? OK : fail('iban_checksum', 'IBAN checksum failed')
}Use in a template
Validators attach to a field on a custom template. The cascade runs them after mapping but before commit; failures surface in the per-row validation report.
fields:
- column: iban
type: string
validators:
- type: iban
countries: [CH, LI, DE, FR, IT]Common gotchas
- Country length is enforced only via the global 4–32 char total (`[A-Z0-9]{11,30}` after the 4-char prefix). Swiss IBANs are 21 chars, German 22, Maltese 31 — the validator does not enforce per-country length.
- Whitespace is stripped before checksum; case is normalised. `"ch93 0076..."` works.
- No bank-code lookup. A syntactically valid IBAN can still point at a closed account.
- Opt-in `strict: true` enforces per-country length against the SWIFT IBAN Registry (CH=21, DE=22, FR=27, GB=22, MT=31, …) in addition to the mod-97 checksum. A wrong length returns `iban_length`; an unrecognised country prefix returns `iban_country`. Default behavior is unchanged.
Related templates
Names, AHV/GLN, contract type, address.
Fields: iban
Supplier catalogue with GTIN/IBAN/GLN.
Fields: iban
Pricing
Validators run on every committed row
Schema-only mode (headers + ≤3 sample rows) is free and unlimited; full-data commits are metered. See plans →