Giter Site home page Giter Site logo

jacekkarczmarczyk / iban-validation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jschaedl/iban-validation

0.0 1.0 0.0 246 KB

:bank: A small library for validating International BankAccount Numbers (IBANs)

License: MIT License

PHP 99.29% Makefile 0.71%

iban-validation's Introduction

iban-validation

StandWithUkraine

SWUbanner

A message to Russian 🇷🇺 people

If you currently live in Russia, please read this message.

Purpose

A small library for validating International Bankaccount Numbers (IBANs) based on the IBAN Registry provided by SWIFT. See https://www.swift.com/standards/data-standards/iban for more information.

.github/workflows/ci.yaml PHP Version Latest Stable Version Latest Unstable Version Total Downloads License

Development status

This library is ready to use. The Iban validation should be fine, but there is no warranty. Please use it at your own risk.


Features

  • full country support of IBAN validation based on SWIFT Registry
  • customizable violation messages
  • simple to use object-oriented api
  • high test coverage
  • DIC friendly

Installation

To install jschaedl/iban-validation via composer use

$ composer require jschaedl/iban-validation

You can see this library on Packagist.


Iban Validation

<?php

use Iban\Validation\Validator;
use Iban\Validation\Iban;

$iban = new Iban('DE89 3704 0044 0532 0130 00');
$validator = new Validator();

if (!$validator->validate($iban)) {
    foreach ($validator->getViolations() as $violation) {
        echo $violation;
    }
}

You can also customize the violation messages by providing them via configuration. Just create a Validator passing a config array as constructor argument.

<?php

use Iban\Validation\Validator;

$validator = new Validator([
    'violation.unsupported_country' => 'The requested country is not supported!',
    'violation.invalid_length' => 'The length of the given Iban is not valid!',
    'violation.invalid_format' => 'The format of the given Iban is not valid!',
    'violation.invalid_checksum' => 'The checksum of the given Iban is not valid!',
]);

You can pass true to the second argument of the Validator::validate(string|Iban $iban, bool $throw = false) in order to retrieve exceptions thrown on validation errors.

$validator = new Validator();

try {
    $validator->validate(new Iban('DE89 3704 0044 0532 0130 00'), throw: true);
} catch (Exception $exception) {
    // ...
}

Iban Information

<?php

use Iban\Validation\Iban;
use Iban\Validation\CountryInfo;

$iban = new Iban('IBAN DE89 3704 0044 0532 0130 00');
$iban->countryCode(); // 'DE'
$iban->checksum(); // '89'
$iban->bban(); // '370400440532013000'
$iban->bbanBankIdentifier(); // '37040044'
$iban->format(Iban::FORMAT_PRINT); // 'DE89 3704 0044 0532 0130 00'
$iban->format(Iban::FORMAT_ELECTRONIC); // 'DE89370400440532013000'
$iban->format(Iban::FORMAT_ANONYMIZED); // 'XXXXXXXXXXXXXXXXXX3000'

$countryInfo = new CountryInfo('DE');
$countryInfo->getCountryName(); // 'Germany'
$countryInfo->getIbanStructureSwift(); // 'DE2!n8!n10!n'
$countryInfo->getBbanStructureSwift(); // '8!n10!n'
$countryInfo->getIbanRegex(); // '/^DE\d{2}\d{8}\d{10}$/'
$countryInfo->getBbanRegex(); // '/^\d{8}\d{10}$/'
$countryInfo->getIbanLength(); // 22
$countryInfo->getBbanLength(); // 18
$countryInfo->getIbanPrintExample(); // 'DE89 3704 0044 0532 0130 00'
$countryInfo->getIbanElectronicExample(); // 'DE89370400440532013000'

How to contribute

If you want to fix some bugs or want to enhance some functionality, please fork one of the release branches and create your own development branch. Then fix the bug you found or add your enhancements and make a pull request. Please commit your changes in tiny steps and add a detailed description on every commit.

Unit Testing

All pull requests must be accompanied by passing unit tests. This repository uses PHPUnit and Composer. You must run composer --dev install to install this package's dependencies. You can run the tests via:

$ make it && make tests

Author

Jan Schädlich

Contributors

License

MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.