Comparing version 3.2.5 to 3.3.0
@@ -16,5 +16,31 @@ /*! | ||
* ``` | ||
*/ | ||
v */ | ||
export declare function isValidIBAN(iban: string): boolean; | ||
/** | ||
* IBAM validation errors | ||
*/ | ||
export declare enum ValidationErrorsIBAN { | ||
NoIBANProvided = 0, | ||
NoIBANCountry = 1, | ||
WrongBBANLength = 2, | ||
WrongBBANFormat = 3, | ||
ChecksumNotNumber = 4, | ||
WrongIBANChecksum = 5 | ||
} | ||
/** | ||
* Interface for ValidateIBAN result | ||
*/ | ||
export interface ValidateIBANResult { | ||
errorCodes: ValidationErrorsIBAN[]; | ||
valid: boolean; | ||
} | ||
/** | ||
* validateIBAN | ||
* ``` | ||
* // returns {errorCodes: [], valid: true} | ||
* ibantools.validateIBAN("NL91 ABNA 0417 1643 00"); | ||
* ``` | ||
*/ | ||
export declare function validateIBAN(iban?: string): ValidateIBANResult; | ||
/** | ||
* Validate BBAN | ||
@@ -118,3 +144,3 @@ * | ||
* $("input#iban").value($(this).val()); | ||
* // Add new value to "pattern" attribute to #iban input text field | ||
* // Add New value to "pattern" attribute to #iban input text field | ||
* $("input#iban").attr("pattern", $(this).val() + "[0-9]{2}" + country.bban_regexp.slice(1).replace("$","")); | ||
@@ -144,2 +170,25 @@ * }); | ||
/** | ||
* BIC validation errors | ||
*/ | ||
export declare enum ValidationErrorsBIC { | ||
NoBICProvided = 0, | ||
NoBICCountry = 1, | ||
WrongBICFormat = 2 | ||
} | ||
/** | ||
* Interface for ValidateBIC result | ||
*/ | ||
export interface ValidateBICResult { | ||
errorCodes: ValidationErrorsBIC[]; | ||
valid: boolean; | ||
} | ||
/** | ||
* validateBIC | ||
* ``` | ||
* // returns {errorCodes: [], valid: true} | ||
* ibantools.validateBIC("NEDSZAJJXXX"); | ||
* ``` | ||
*/ | ||
export declare function validateBIC(bic?: string): ValidateBICResult; | ||
/** | ||
* Interface for ExtractBIC result | ||
@@ -146,0 +195,0 @@ */ |
@@ -11,3 +11,3 @@ /*! | ||
* @module ibantools | ||
* @version 3.2.5 | ||
* @version 3.3.0 | ||
* @license MPL-2.0 | ||
@@ -18,3 +18,3 @@ * @preferred | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.countrySpecs = exports.extractBIC = exports.isValidBIC = exports.getCountrySpecifications = exports.friendlyFormatIBAN = exports.electronicFormatIBAN = exports.extractIBAN = exports.composeIBAN = exports.isSEPACountry = exports.isValidBBAN = exports.isValidIBAN = void 0; | ||
exports.countrySpecs = exports.extractBIC = exports.validateBIC = exports.ValidationErrorsBIC = exports.isValidBIC = exports.getCountrySpecifications = exports.friendlyFormatIBAN = exports.electronicFormatIBAN = exports.extractIBAN = exports.composeIBAN = exports.isSEPACountry = exports.isValidBBAN = exports.validateIBAN = exports.ValidationErrorsIBAN = exports.isValidIBAN = void 0; | ||
/** | ||
@@ -30,3 +30,3 @@ * Validate IBAN | ||
* ``` | ||
*/ | ||
v */ | ||
function isValidIBAN(iban) { | ||
@@ -51,2 +51,56 @@ if (iban !== undefined && iban !== null) { | ||
/** | ||
* IBAM validation errors | ||
*/ | ||
var ValidationErrorsIBAN; | ||
(function (ValidationErrorsIBAN) { | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["NoIBANProvided"] = 0] = "NoIBANProvided"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["NoIBANCountry"] = 1] = "NoIBANCountry"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["WrongBBANLength"] = 2] = "WrongBBANLength"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["WrongBBANFormat"] = 3] = "WrongBBANFormat"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["ChecksumNotNumber"] = 4] = "ChecksumNotNumber"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["WrongIBANChecksum"] = 5] = "WrongIBANChecksum"; | ||
})(ValidationErrorsIBAN = exports.ValidationErrorsIBAN || (exports.ValidationErrorsIBAN = {})); | ||
/** | ||
* validateIBAN | ||
* ``` | ||
* // returns {errorCodes: [], valid: true} | ||
* ibantools.validateIBAN("NL91 ABNA 0417 1643 00"); | ||
* ``` | ||
*/ | ||
function validateIBAN(iban) { | ||
var result = { errorCodes: [], valid: true }; | ||
if (iban !== undefined && iban !== null && iban !== '') { | ||
var spec = exports.countrySpecs[iban.slice(0, 2)]; | ||
if (spec === undefined) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.NoIBANCountry); | ||
} | ||
else { | ||
if (spec.chars !== iban.length) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.WrongBBANLength); | ||
} | ||
if (spec.bban_regexp && !checkFormatBBAN(iban.slice(4), spec.bban_regexp)) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.WrongBBANFormat); | ||
} | ||
var reg = new RegExp('^[0-9]{2}$', ''); | ||
if (!reg.test(iban.slice(2, 4))) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.ChecksumNotNumber); | ||
} | ||
if (!isValidIBANChecksum(iban)) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.WrongIBANChecksum); | ||
} | ||
} | ||
} | ||
else { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.NoIBANProvided); | ||
} | ||
return result; | ||
} | ||
exports.validateIBAN = validateIBAN; | ||
/** | ||
* Validate BBAN | ||
@@ -267,3 +321,3 @@ * | ||
* $("input#iban").value($(this).val()); | ||
* // Add new value to "pattern" attribute to #iban input text field | ||
* // Add New value to "pattern" attribute to #iban input text field | ||
* $("input#iban").attr("pattern", $(this).val() + "[0-9]{2}" + country.bban_regexp.slice(1).replace("$","")); | ||
@@ -314,2 +368,41 @@ * }); | ||
/** | ||
* BIC validation errors | ||
*/ | ||
var ValidationErrorsBIC; | ||
(function (ValidationErrorsBIC) { | ||
ValidationErrorsBIC[ValidationErrorsBIC["NoBICProvided"] = 0] = "NoBICProvided"; | ||
ValidationErrorsBIC[ValidationErrorsBIC["NoBICCountry"] = 1] = "NoBICCountry"; | ||
ValidationErrorsBIC[ValidationErrorsBIC["WrongBICFormat"] = 2] = "WrongBICFormat"; | ||
})(ValidationErrorsBIC = exports.ValidationErrorsBIC || (exports.ValidationErrorsBIC = {})); | ||
/** | ||
* validateBIC | ||
* ``` | ||
* // returns {errorCodes: [], valid: true} | ||
* ibantools.validateBIC("NEDSZAJJXXX"); | ||
* ``` | ||
*/ | ||
function validateBIC(bic) { | ||
var result = { errorCodes: [], valid: true }; | ||
if (bic !== undefined && bic !== null && bic !== '') { | ||
var spec = exports.countrySpecs[bic.toUpperCase().slice(4, 6)]; | ||
if (spec === undefined) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsBIC.NoBICCountry); | ||
} | ||
else { | ||
var reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$', ''); | ||
if (!reg.test(bic)) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsBIC.WrongBICFormat); | ||
} | ||
} | ||
} | ||
else { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsBIC.NoBICProvided); | ||
} | ||
return result; | ||
} | ||
exports.validateBIC = validateBIC; | ||
/** | ||
* extractBIC | ||
@@ -316,0 +409,0 @@ * ``` |
@@ -11,3 +11,3 @@ /*! | ||
* @module ibantools | ||
* @version 3.2.5 | ||
* @version 3.3.0 | ||
* @license MPL-2.0 | ||
@@ -27,3 +27,3 @@ * @preferred | ||
* ``` | ||
*/ | ||
v */ | ||
export function isValidIBAN(iban) { | ||
@@ -47,2 +47,55 @@ if (iban !== undefined && iban !== null) { | ||
/** | ||
* IBAM validation errors | ||
*/ | ||
export var ValidationErrorsIBAN; | ||
(function (ValidationErrorsIBAN) { | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["NoIBANProvided"] = 0] = "NoIBANProvided"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["NoIBANCountry"] = 1] = "NoIBANCountry"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["WrongBBANLength"] = 2] = "WrongBBANLength"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["WrongBBANFormat"] = 3] = "WrongBBANFormat"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["ChecksumNotNumber"] = 4] = "ChecksumNotNumber"; | ||
ValidationErrorsIBAN[ValidationErrorsIBAN["WrongIBANChecksum"] = 5] = "WrongIBANChecksum"; | ||
})(ValidationErrorsIBAN || (ValidationErrorsIBAN = {})); | ||
/** | ||
* validateIBAN | ||
* ``` | ||
* // returns {errorCodes: [], valid: true} | ||
* ibantools.validateIBAN("NL91 ABNA 0417 1643 00"); | ||
* ``` | ||
*/ | ||
export function validateIBAN(iban) { | ||
var result = { errorCodes: [], valid: true }; | ||
if (iban !== undefined && iban !== null && iban !== '') { | ||
var spec = countrySpecs[iban.slice(0, 2)]; | ||
if (spec === undefined) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.NoIBANCountry); | ||
} | ||
else { | ||
if (spec.chars !== iban.length) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.WrongBBANLength); | ||
} | ||
if (spec.bban_regexp && !checkFormatBBAN(iban.slice(4), spec.bban_regexp)) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.WrongBBANFormat); | ||
} | ||
var reg = new RegExp('^[0-9]{2}$', ''); | ||
if (!reg.test(iban.slice(2, 4))) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.ChecksumNotNumber); | ||
} | ||
if (!isValidIBANChecksum(iban)) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.WrongIBANChecksum); | ||
} | ||
} | ||
} | ||
else { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsIBAN.NoIBANProvided); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Validate BBAN | ||
@@ -257,3 +310,3 @@ * | ||
* $("input#iban").value($(this).val()); | ||
* // Add new value to "pattern" attribute to #iban input text field | ||
* // Add New value to "pattern" attribute to #iban input text field | ||
* $("input#iban").attr("pattern", $(this).val() + "[0-9]{2}" + country.bban_regexp.slice(1).replace("$","")); | ||
@@ -302,2 +355,40 @@ * }); | ||
/** | ||
* BIC validation errors | ||
*/ | ||
export var ValidationErrorsBIC; | ||
(function (ValidationErrorsBIC) { | ||
ValidationErrorsBIC[ValidationErrorsBIC["NoBICProvided"] = 0] = "NoBICProvided"; | ||
ValidationErrorsBIC[ValidationErrorsBIC["NoBICCountry"] = 1] = "NoBICCountry"; | ||
ValidationErrorsBIC[ValidationErrorsBIC["WrongBICFormat"] = 2] = "WrongBICFormat"; | ||
})(ValidationErrorsBIC || (ValidationErrorsBIC = {})); | ||
/** | ||
* validateBIC | ||
* ``` | ||
* // returns {errorCodes: [], valid: true} | ||
* ibantools.validateBIC("NEDSZAJJXXX"); | ||
* ``` | ||
*/ | ||
export function validateBIC(bic) { | ||
var result = { errorCodes: [], valid: true }; | ||
if (bic !== undefined && bic !== null && bic !== '') { | ||
var spec = countrySpecs[bic.toUpperCase().slice(4, 6)]; | ||
if (spec === undefined) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsBIC.NoBICCountry); | ||
} | ||
else { | ||
var reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$', ''); | ||
if (!reg.test(bic)) { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsBIC.WrongBICFormat); | ||
} | ||
} | ||
} | ||
else { | ||
result.valid = false; | ||
result.errorCodes.push(ValidationErrorsBIC.NoBICProvided); | ||
} | ||
return result; | ||
} | ||
/** | ||
* extractBIC | ||
@@ -304,0 +395,0 @@ * ``` |
{ | ||
"name": "ibantools", | ||
"version": "3.2.5", | ||
"version": "3.3.0", | ||
"description": "Validation, extraction and creation of IBAN, BBAN, BIC/SWIFT numbers plus some other helpful stuff like ISO 3136-1 alpha 2 country list", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -46,2 +46,8 @@ # IBANTools | ||
ibantools.isValidIBAN(iban); | ||
// If you want to know reason why IBAN is invalid | ||
ibantools.validateIBAN('NL91ABNA0517164300'); | ||
// Returns { valid: false, errorCodes: [iban.ValidationErrorsIBAN.WrongIBANChecksum] } | ||
// Validate BIC | ||
ibantools.isValidBIC('ABNANL2A'); | ||
@@ -48,0 +54,0 @@ ``` |
Sorry, the diff of this file is not supported yet
89523
2322
90