IBAN Validator for your web application forms (Angular, React, Vue, ...), comes without any dependencies and can be used as a standalone function in any JS project. It can perform format, digit and length IBAN validations. Currently 108 countries are supp
npm install ngx-iban-validatorIBAN Validator for your web application forms (Angular, React, Vue, ...), comes without any dependencies and can be used as a standalone function in any JS project. It can perform format, digit and length IBAN validations. Currently 112 countries are supported.
- Zero external dependencies
- Works in Node.js and all modern browsers
- Works with TypeScript and plain JS
- Install
- Basic usage
- Error Response
- Use as a form validator
- Angular example
- React example
- Demo Applications
- Supported countries
- Changelog
- Contributing
- Code of Conduct
- License
- Read more
npm
``bash`
npm i ngx-iban-validator
pnpm
`bash`
pnpm add ngx-iban-validator
yarn
`bash`
yarn add ngx-iban-validator
You can use validateIBAN function independently from any forms.
Value can be passed as part of object in this case validation flow will be the same as for form validation:
- If IBAN is valid as result of validation null is returned.
- If IBAN is invalid and some of the checks fail IBANValidationResult object is returned containing more info about error.
`typescript`
const ibanIsInvalid =
validateIBAN({
value: 'AL35202111090000000001234567',
}) !== null;
Value can be passed as a string:
- For valid and invalid IBAN IBANValidationResult object is returned
`bash`
const ibanIsInvalid = validateIBAN("AL35202111090000000001234567").ibanInvalid;
`javascript`
const ibanValidator = require('ngx-iban-validator');
const ibanIsInvalid = ibanValidator.validateIBAN(
'BA393385804800211234'
).ibanInvalid;
- If IBAN is valid as result of validation null is returned.
- If IBAN is invalid and some of the checks fail IBANValidationResult object is returned containing more info about error.
`typescript
export interface IBANValidationResult {
ibanInvalid: boolean;
error: IBANError | null;
}
export interface IBANError {
countryUnsupported: boolean;
codeLengthInvalid: boolean;
patternInvalid: boolean;
}
`
Error object contains more details about validation error. You can display errors easily as with any other validator.
Import validateIBAN function from ngx-iban-validator package into your component file. Add validateIBAN to your form validators array.
`ts
import { Component, inject } from '@angular/core';
import { NgIf } from '@angular/common';
import {
FormBuilder,
FormGroup,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { validateIBAN } from 'ngx-iban-validator';
@Component({
selector: 'my-app',
standalone: true,
imports: [NgIf, ReactiveFormsModule],
template:
,
styles: [
,
],
})
export class App {
formBuilder = inject(FormBuilder);
ibanForm = this.formBuilder.group({
iban: [null, [Validators.required, validateIBAN]],
});
submit(form: FormGroup) {
const { valid, value } = form;
const { iban } = value;
if (valid) {
alert(IBAN: ${iban}, is valid!);
}
}
}
`$3
`tsx
import { useState } from 'react';import {
type IBANError,
type IBANValidationResult,
validateIBAN,
} from 'ngx-iban-validator';
import './App.css';
function App() {
const [error, setError] = useState(null);
const validate = (iban: string): boolean => {
const validation = validateIBAN({
value: iban,
});
if (validation) {
const { ibanInvalid, error }: IBANValidationResult = validation;
if (ibanInvalid) {
setError(error);
return false;
} else {
setError(null);
return true;
}
} else {
setError(null);
return true;
}
};
const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const iban = formData.get('iban') as string;
const validation = validate(iban);
if (validation) {
alert(
IBAN: ${iban}, is valid!);
} else {
alert(IBAN: ${iban}, is invalid!);
}
}; const handleIbanChanged = (event: React.ChangeEvent) => {
const { value } = event.target;
validate(value);
};
return (
);
}export default App;
``Check demo applications for usage examples:
- Angular - Demo Application
- React - Demo Application