diff --git a/README.md b/README.md
index 25af675ed..fc12f70ea 100644
--- a/README.md
+++ b/README.md
@@ -126,6 +126,7 @@ Validator | Description
**isISO8601(str)** | check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date.
`options` is an object which defaults to `{ strict: false, strictSeparator: false }`. If `strict` is true, date strings with invalid dates like `2009-02-29` will be invalid. If `strictSeparator` is true, date strings with date and time separated by anything other than a T will be invalid.
**isISO31661Alpha2(str)** | check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code.
**isISO31661Alpha3(str)** | check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code.
+**isISO4217(str)** | check if the string is a valid [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) officially assigned currency code.
**isISRC(str)** | check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code).
**isISSN(str [, options])** | check if the string is an [ISSN](https://en.wikipedia.org/wiki/International_Standard_Serial_Number).
`options` is an object which defaults to `{ case_sensitive: false, require_hyphen: false }`. If `case_sensitive` is true, ISSNs with a lowercase `'x'` as the check digit are rejected.
**isJSON(str [, options])** | check if the string is valid JSON (note: uses JSON.parse).
`options` is an object which defaults to `{ allow_primitives: false }`. If `allow_primitives` is true, the primitives 'true', 'false' and 'null' are accepted as valid JSON values.
diff --git a/src/index.js b/src/index.js
index 59b813c1f..a0e8aa63c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -90,6 +90,7 @@ import isISO8601 from './lib/isISO8601';
import isRFC3339 from './lib/isRFC3339';
import isISO31661Alpha2 from './lib/isISO31661Alpha2';
import isISO31661Alpha3 from './lib/isISO31661Alpha3';
+import isISO4217 from './lib/isISO4217';
import isBase32 from './lib/isBase32';
import isBase58 from './lib/isBase58';
@@ -198,6 +199,7 @@ const validator = {
isRFC3339,
isISO31661Alpha2,
isISO31661Alpha3,
+ isISO4217,
isBase32,
isBase58,
isBase64,
diff --git a/src/lib/isISO4217.js b/src/lib/isISO4217.js
new file mode 100644
index 000000000..0738614c9
--- /dev/null
+++ b/src/lib/isISO4217.js
@@ -0,0 +1,38 @@
+import assertString from './util/assertString';
+
+// from https://en.wikipedia.org/wiki/ISO_4217
+const validISO4217CurrencyCodes = new Set([
+ 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN',
+ 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD',
+ 'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK',
+ 'DJF', 'DKK', 'DOP', 'DZD',
+ 'EGP', 'ERN', 'ETB', 'EUR',
+ 'FJD', 'FKP',
+ 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD',
+ 'HKD', 'HNL', 'HRK', 'HTG', 'HUF',
+ 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK',
+ 'JMD', 'JOD', 'JPY',
+ 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT',
+ 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD',
+ 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN',
+ 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD',
+ 'OMR',
+ 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG',
+ 'QAR',
+ 'RON', 'RSD', 'RUB', 'RWF',
+ 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL',
+ 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS',
+ 'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS',
+ 'VES', 'VND', 'VUV',
+ 'WST',
+ 'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX',
+ 'YER',
+ 'ZAR', 'ZMW', 'ZWL',
+]);
+
+export default function isISO4217(str) {
+ assertString(str);
+ return validISO4217CurrencyCodes.has(str.toUpperCase());
+}
+
+export const CurrencyCodes = validISO4217CurrencyCodes;
diff --git a/test/validators.js b/test/validators.js
index 6bb607282..ef9c66aec 100644
--- a/test/validators.js
+++ b/test/validators.js
@@ -9242,6 +9242,36 @@ describe('Validators', () => {
});
});
+ it('should validate ISO 4217 corrency codes', () => {
+ // from https://en.wikipedia.org/wiki/ISO_4217
+ test({
+ validator: 'isISO4217',
+ valid: [
+ 'AED',
+ 'aed',
+ 'AUD',
+ 'CUC',
+ 'EUR',
+ 'GBP',
+ 'LYD',
+ 'MYR',
+ 'SGD',
+ 'USD',
+ ],
+ invalid: [
+ '',
+ '$',
+ 'US',
+ 'us',
+ 'AAA',
+ 'aaa',
+ 'RWA',
+ 'EURO',
+ 'euro',
+ ],
+ });
+ });
+
it('should validate whitelisted characters', () => {
test({
validator: 'isWhitelisted',