# Getting started (laravel-rust-iban)

> This page shows how to add laravel-rust-iban to a project, validate a pasted IBAN and handle the errors.

- Package: laravel-rust-iban (Laravel for Rust, alpha), crates: `laravel-rust-iban`, `laravel-rust-iban-core`
- Maintenance: active; Latest release: 0.1.0 (2026-12-05); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-iban), [crates.io](https://crates.io/crates/laravel-rust-iban/0.1.0), [docs.rs](https://docs.rs/laravel-rust-iban/0.1.0), [Changelog](https://oss.bowerbird.si/iban/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-iban/blob/322f32ccaf92144d5d5727285efc84ca03fd603e/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-iban/blob/322f32ccaf92144d5d5727285efc84ca03fd603e/SECURITY.md)
- Based on: [globalcitizen/php-iban](https://github.com/globalcitizen/php-iban): Reference behavior for the independent Rust implementation.
- PHP parity: core (14 covered, 34 diverged, 11 planned of 59 abilities; 565 fixtures; follows globalcitizen/php-iban v5.03b; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/iban/docs/getting-started/
- Source: https://github.com/bowerbird-si/laravel-rust-iban/blob/322f32ccaf92144d5d5727285efc84ca03fd603e/docs/getting-started.md

This page shows how to add laravel-rust-iban to a project, validate a pasted IBAN and handle the errors.

## Install

In a Laravel for Rust application, add the adapter crate:

```toml
[dependencies]
laravel-rust-iban = { git = "https://github.com/bowerbird-si/laravel-rust-iban" }
```

Turn on the `minijinja` feature to get the [template filters](https://oss.bowerbird.si/iban/docs/validation/#template-filters):

```toml
[dependencies]
laravel-rust-iban = { git = "https://github.com/bowerbird-si/laravel-rust-iban", features = ["minijinja"] }
```

Outside Laravel, depend on the core crate only. It has no runtime dependencies:

```toml
[dependencies]
laravel-rust-iban-core = { git = "https://github.com/bowerbird-si/laravel-rust-iban" }
```

The adapter re-exports everything in the core, so the examples in these docs use `laravel_rust_iban`.
With the core crate, write `laravel_rust_iban_core` instead.

## Parse an IBAN

`Iban::parse` accepts the way people paste an IBAN: lower case, spaces, dashes and a leading `IBAN`
tag. It returns a validated `Iban` or an `Error`.

```rust
use laravel_rust_iban::{Iban, NationalCheck};

fn main() -> Result<(), laravel_rust_iban::Error> {
    let iban = Iban::parse("IBAN be68-5390-0754-7034")?;

    assert_eq!(iban.to_string(), "BE68539007547034");
    assert_eq!(iban.human_format(), "BE68 5390 0754 7034");
    assert_eq!(iban.country().name(), "Belgium");
    assert_eq!(iban.bank(), Some("539"));
    assert_eq!(iban.national_check(), NationalCheck::Valid);
    Ok(())
}
```

`Iban` also implements `FromStr`, so `"be68 5390 0754 7034".parse::<Iban>()` works the same way.
Its `Display` and `AsRef<str>` give the electronic form, and its `Debug` output masks the account
number, so a logged `Iban` shows `Iban("BE** **** **** 7034")`.

To check without keeping the value, use `verify`:

```rust
fn main() {
    assert!(laravel_rust_iban::verify("be68 5390 0754 7034"));
    assert!(!laravel_rust_iban::verify("BE68 5390 0754 7035"));
}
```

## Errors

Parsing checks the input in a fixed order and returns the first problem it finds. The error messages
never contain the input, so they are safe to log.

| `Error` | When | Message |
| --- | --- | --- |
| `InputTooLong` | The input is longer than 1024 bytes | `IBAN input exceeds 1024 bytes` |
| `NotMachineFormat` | Strict parsing found a byte other than `A`–`Z` or `0`–`9` | `IBAN must use electronic format` |
| `InvalidLength` | Fewer than 5 or more than 34 characters, or not the country's IBAN length | `IBAN input has an invalid length` |
| `InvalidStructure` | The first two characters are not letters, the check digits are not digits, or the BBAN does not fit the country's structure | `IBAN input has an invalid structure` |
| `UnknownCountry` | The prefix is not in the registry | `IBAN country is unsupported` |
| `NonCanonicalCheckDigits` | The check digits are `00`, `01` or `99` | `IBAN check digits must be between 02 and 98` |
| `InvalidCheckDigits` | The MOD 97-10 check fails | `IBAN check digits are invalid` |

Two more variants come from the [national check digit](https://oss.bowerbird.si/iban/docs/national-check-digits/) functions:
`UnsupportedNationalCheck` and `InvalidNationalCheckDigits`. The enum is `#[non_exhaustive]`.

```rust
use laravel_rust_iban::{Error, Iban};

fn main() {
    assert_eq!(Iban::parse("BE68 5390 0754 7035"), Err(Error::InvalidCheckDigits));
    assert_eq!(Iban::parse("BE68 5390 0754 703"), Err(Error::InvalidLength));
    assert_eq!(Iban::parse("BE01 5390 0754 7034"), Err(Error::NonCanonicalCheckDigits));

    let error = Iban::parse("BE68 5390 0754 7035").unwrap_err();
    assert_eq!(error.to_string(), "IBAN check digits are invalid");
}
```

## Next steps

- [Working with IBANs](https://oss.bowerbird.si/iban/docs/ibans/): formats, parts, strict parsing and check digits.
- [Validation and templates](https://oss.bowerbird.si/iban/docs/validation/): the `IbanRule` and the template filters.
