validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

`isBIC` country code does not accept `XK`

Open ejcheng opened this issue 3 years ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

The isBIC validator uses the list of country codes in './isISO31661Alpha2' and that list of country codes does not include "XK" (Republic of Kosovo).

However, on the ISO 9362 page, Wikipedia says that the country code in a SWIFT/BIC code is "a ISO 3166-1 alpha-2 country code (exceptionally, SWIFT has assigned the code XK to Republic of Kosovo, which does not have an ISO 3166-1 country code)".

Kosovo's code is not in the ISO 3166-1 alpha-2, but for assigning BIC country codes, it is a valid code.

Because isBIC only uses the list of country codes on the ISO 3166-1 alpha-2 format, a BIC code with "XK" as the country code would not pass.

https://github.com/validatorjs/validator.js/blob/86a07ba4f3f710f639e92a62cf81dd3321ef9ee8/src/lib/isBIC.js#L12-L14

We should change the check above in isBIC.js to this to account for "XK" being an allowed country code:

if (!CountryCodes.has(str.slice(4, 6).toUpperCase()) && str.slice(4, 6).toUpperCase() !== "XK" ) {
    return false;
  }

Examples If applicable, add screenshots to help explain your problem.

Additional context Validator.js version: 13.7.0 Node.js version: 16 OS platform: [windows, linux, macOS, etc]: Linux

ejcheng avatar Sep 20 '22 17:09 ejcheng

Feel free to open a PR for this

WikiRik avatar Sep 20 '22 17:09 WikiRik

Example:

https://wise.com/de/swift-codes/CBRKXKPRXXX

ST-DDT avatar Sep 20 '22 17:09 ST-DDT