CrystalIBAN::Validator
Validates IBAN strings against the ISO 13616 standard.
Constructors
new(*, registry : StructureRegistry)
Creates a validator using a shared StructureRegistry. Use this when you also have a Generator to avoid parsing the JSON twice.
registry = CrystalIBAN::StructureRegistry.new
gen = CrystalIBAN::Generator.new(registry: registry)
val = CrystalIBAN::Validator.new(registry: registry)
Class methods
Returns true if iban is valid using the bundled default registry.
CrystalIBAN::Validator.valid?("LI05 0881 0061 8828 4") # => true
Instance methods
Returns true if iban is structurally valid for its country and passes the ISO 13616 MOD-97 checksum. Leading/trailing whitespace and internal spaces are stripped; the string is uppercased before checking.
val = CrystalIBAN::Validator.new
val.valid?("LI05 0881 0061 8828 4") # => true
val.valid?("LI00 0000 0000 0000 0") # => false (bad checksum)
val.valid?("XX123") # => false (unknown country)
Returns the normalized IBAN (uppercased, spaces removed) if it is valid, or raises ArgumentError with a human-readable explanation of the failure.
Checks performed in order:
- Minimum length (≥ 4 characters after stripping spaces)
- Country code is supported by the loaded structure data
- Total length matches the country's expected IBAN length
- MOD-97 checksum equals 1 (ISO 13616)
val = CrystalIBAN::Validator.new
val.validate!("LI05 0881 0061 8828 4") # => "LI050881006188284"
val.validate!("LI00 0000 0000 0000 0") # raises ArgumentError