diff --git a/src/lib/isCurrency.js b/src/lib/isCurrency.js old mode 100644 new mode 100755 index 8cea9fbda..54b1f7c7c --- a/src/lib/isCurrency.js +++ b/src/lib/isCurrency.js @@ -4,8 +4,9 @@ import assertString from './util/assertString'; function currencyRegex(options) { let decimal_digits = `\\d{${options.digits_after_decimal[0]}}`; options.digits_after_decimal.forEach((digit, index) => { if (index !== 0) decimal_digits = `${decimal_digits}|\\d{${digit}}`; }); + const symbol = - `(\\${options.symbol.replace(/\./g, '\\.')})${(options.require_symbol ? '' : '?')}`, + `(${options.symbol.replace(/\W/, m => `\\${m}`)})${(options.require_symbol ? '' : '?')}`, negative = '-?', whole_dollar_amount_without_sep = '[1-9]\\d*', whole_dollar_amount_with_sep = `[1-9]\\d{0,2}(\\${options.thousands_separator}\\d{3})*`, diff --git a/test/validators.js b/test/validators.js old mode 100644 new mode 100755 index 76672cef2..eeeb3c957 --- a/test/validators.js +++ b/test/validators.js @@ -7293,7 +7293,6 @@ describe('Validators', () => { '(-$)', ], }); - // $##,###.## with no negatives (en-US, en-CA, en-AU, en-HK) test({ validator: 'isCurrency', @@ -7348,6 +7347,29 @@ describe('Validators', () => { '-$10,123.45', ], }); + + // R$ ##,###.## (pt_BR) + test({ + validator: 'isCurrency', + args: [ + { + symbol: 'R$', + require_symbol: true, + allow_space_after_symbol: true, + symbol_after_digits: false, + thousands_separator: '.', + decimal_separator: ',', + }, + ], + valid: [ + 'R$ 1.400,00', + 'R$ 400,00', + ], + invalid: [ + '$ 1.400,00', + '$R 1.400,00', + ], + }); }); it('should validate Ethereum addresses', () => {