feat(isIBAN): add white and blacklist options to the isIBAN validator by edilson · Pull Request #2235 · validatorjs/validator.js

feat(isIBAN): add white and blacklist options to the isIBAN validator

In order to restrict the list of countries that I want to validate the IBAN against now we can pass the whitelist option with the country codes that I want to validate the code. Also if I want to remove a certain country from the validation now I will have the blacklist option and the countries passed there will be removed from validation.

So, if you use the isIBAN validator and pass a the whitelist option and the country from the IBAN code is not on the whitelist, it will return an error:

import isIBAN from 'validator/lib/isIBAN';

isIBAN('GB29NWBK60161331926819', { whitelist: ['IT'] })

Error: IBAN code does not belong to one of the countries listed on whitelist!

And if you use the same validator with the blacklist option it should return an error if the code passed is from one of the countries listed:

import isIBAN from 'validator/lib/isIBAN';

isIBAN('GB29NWBK60161331926819', { blacklist: ['GB'] })

Error: IBAN code belongs to one of the countries listed on blacklist!

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)