Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift IBAN Validator

A comprehensive IBAN and SWIFT/BIC validation library for Swift. Validate international bank account numbers with ISO 13616 mod-97 checksum verification, validate SWIFT/BIC codes, and extract structured components — all through natural String, Array, and Collection extensions. Perfect for fintech apps, payment forms, and banking integrations.

Features

  • 🎯 IBAN validation — Length, structure, and mod-97 checksum verification per ISO 13616.
  • 🏦 SWIFT/BIC validation — Validate 8- or 11-character SWIFT/BIC codes (also available as isBIC).
  • 🌍 Country awareness — Resolve the country code and human-readable country name from an IBAN.
  • 🔍 Component extraction — Pull check digits, bank code, and country code from any valid IBAN.
  • 🧱 SWIFT components — Extract bank, country, location, and branch codes, plus a head-office check.
  • 💶 SEPA detection — Identify IBANs from Single Euro Payments Area countries.
  • Normalization & formatting — Get whitespace-free normalized values or nicely spaced 4-character groups.
  • 📚 Array helpersvalidIBANs, validSWIFTCodes, normalizedIBANs, normalizedSWIFTCodes, groupedByCountry, sepaIBANs, hasValidIBANs, hasValidSWIFTCodes.
  • 🔢 Collection countingvalidIBANCount and validSWIFTCount for quick aggregates.
  • 🧱 Zero dependencies — Pure Foundation.

Requirements

  • iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+
  • Swift 6.1+
  • Xcode 16.0+

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/arraypress/swift-iban-validator.git", from: "1.0.0")
]

Usage

Validating

import IBANValidator

"GB82 WEST 1234 5698 7654 32".isIBAN   // true
"DEUTDEFF".isSWIFT                      // true
"DEUTDEFF".isBIC                        // true (alias for isSWIFT)

Inspecting an IBAN

import IBANValidator

let iban = "DE89 3704 0044 0532 0130 00"

iban.normalizedIBAN    // "DE89370400440532013000"
iban.formattedIBAN     // "DE89 3704 0044 0532 0130 00"
iban.ibanCountryCode   // "DE"
iban.ibanCountry       // "Germany"
iban.ibanCheckDigits   // "89"
iban.ibanBankCode      // bank code (country-dependent)
iban.isSEPA            // true

Inspecting a SWIFT/BIC code

import IBANValidator

let swift = "DEUTDEFF500"

swift.normalizedSWIFT     // "DEUTDEFF500"
swift.swiftBankCode       // "DEUT"
swift.swiftCountryCode    // "DE"
swift.swiftLocationCode   // "FF"
swift.swiftBranchCode     // "500"
swift.isHeadOfficeSWIFT   // false

Working with arrays and collections

import IBANValidator

let ibans = ["GB82WEST12345698765432", "invalid", "DE89370400440532013000"]

ibans.validIBANs         // valid entries only
ibans.normalizedIBANs    // normalized valid entries
ibans.groupedByCountry   // ["GB": [...], "DE": [...]]
ibans.sepaIBANs          // SEPA-country IBANs only
ibans.hasValidIBANs      // true
ibans.validIBANCount     // 2

let codes = ["DEUTDEFF", "BADCODE", "BARCGB22"]
codes.validSWIFTCodes        // ["DEUTDEFF", "BARCGB22"]
codes.normalizedSWIFTCodes   // normalized valid codes
codes.hasValidSWIFTCodes     // true
codes.validSWIFTCount        // 2

How It Works

IBAN validation normalizes the input (uppercased, separators removed), checks the country-specific length, then performs the ISO 13616 mod-97 checksum: the first four characters are moved to the end, letters are converted to digits (A=10 … Z=35), and the resulting number must satisfy value mod 97 == 1. SWIFT/BIC validation enforces the 8- or 11-character structure (4 letters bank code, 2 letters country, 2 alphanumeric location, optional 3 alphanumeric branch). Country, SEPA membership, and bank-code extraction are resolved from a built-in country registry.

Testing

swift test

The test suite covers IBAN checksum validation, SWIFT/BIC structure, component extraction, SEPA detection, and the array/collection helpers.

License

MIT License — see LICENSE file for details.

Author

Created by David Sherlock (ArrayPress) in 2026.

About

A comprehensive IBAN and SWIFT/BIC validation library for Swift, supporting all 89 countries from the IBAN Registry Release 99 (December 2024) with ISO 13616 compliance.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages