Package Exports
- slovak-iban-validator
- slovak-iban-validator/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (slovak-iban-validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Slovak IBAN Validator
A TypeScript library for validating Slovak IBAN numbers and retrieving bank information. Includes integration with Yup and Zod validation libraries.
Installation
npm install slovak-iban-validator
# If using with Yup
npm install yup
# If using with Zod
npm install zodUsage
Basic Usage
import { SlovakIBANValidator } from "slovak-iban-validator";
// Validate an IBAN with full details
const result = SlovakIBANValidator.validateIBAN("SK5911000000002610001237");
console.log(result);
// Output:
// {
// valid: true,
// errors: [],
// formatted: 'SK59 1100 0000 0026 1000 1237',
// bank_swift: 'TATRSKBX',
// bank_name: 'Tatra banka, a.s.'
// }
// Example with invalid IBAN
const invalidResult = SlovakIBANValidator.validateIBAN("SK001234");
console.log(invalidResult);
// Output:
// {
// valid: false,
// errors: [
// 'Invalid length: expected 24 characters, got 7',
// 'Invalid format: IBAN should contain only digits after country code'
// ],
// formatted: null,
// bank_swift: null,
// bank_name: null
// }Using with Yup
import { createYupValidator } from "slovak-iban-validator";
import * as yup from "yup";
// Create a schema with Slovak IBAN validation
const schema = yup.object({
iban: createYupValidator().required(),
});
// Validate the IBAN
try {
const result = await schema.validate({ iban: "SK3112000000198742637541" });
console.log(result);
// Output: { iban: 'SK31 1200 0000 1987 4263 7541' }
} catch (error) {
console.error(error.errors);
}Using with Zod
import { createZodValidator } from "slovak-iban-validator";
import { z } from "zod";
// Create a schema with Slovak IBAN validation
const schema = z.object({
iban: createZodValidator(),
});
// Validate the IBAN
const result = schema.safeParse({ iban: "SK3112000000198742637541" });
if (result.success) {
console.log(result.data);
// Output: {
// iban: {
// raw: 'SK3112000000198742637541',
// formatted: 'SK31 1200 0000 1987 4263 7541',
// bank_name: 'Tatra banka, a.s.',
// bank_swift: 'TATRSKBX',
// valid: true
// }
// }
} else {
console.error(result.error);
}Internationalization
The validator supports both Slovak (default) and English error messages. You can change the language using the setLanguage method:
import { SlovakIBANValidator } from "slovak-iban-validator";
// Use English messages
SlovakIBANValidator.setLanguage('en');
// Use Slovak messages (default)
SlovakIBANValidator.setLanguage('sk');
// Example with Slovak messages
const result = SlovakIBANValidator.validateIBAN("SK001234");
console.log(result);
// Output:
// {
// valid: false,
// errors: [
// 'Nesprávna dĺžka: očakávaných 24 znakov, zadaných 7',
// 'Nesprávny formát: IBAN by mal obsahovať iba číslice za kódom krajiny'
// ],
// formatted: null,
// bank_swift: null,
// bank_name: null
// }Features
- Comprehensive IBAN validation
- Detailed error messages
- Formatted IBAN output
- Bank information retrieval (name and SWIFT code)
- TypeScript support with full type definitions
- Integration with Yup and Zod validation libraries
Validation Result
The validateIBAN method returns an object with the following properties:
valid: boolean - indicates if the IBAN is validerrors: string[] - list of validation errors (empty if valid)formatted: string | null - IBAN formatted with spaces for readabilitybank_swift: string | null - SWIFT/BIC code of the bankbank_name: string | null - Name of the bank
License
MIT