Repository: validatorjs/validator.js (js)

Issue:
IsCurrency symbol validation error
Hi devs,

I'm trying use BRL currency in @IsCurrency options, but when I use this setting the validator fails:

```json
{
	symbol: 'R$',
	require_symbol: true,
	allow_space_after_symbol: true,
	symbol_after_digits: false,
	allow_negatives: false,
	parens_for_negatives: false,
	negative_sign_before_digits: false,
	negative_sign_after_digits: false,
	allow_negative_sign_placeholder: false,
	thousands_separator: '.',
	decimal_separator: ',',
	allow_decimal: true,
	require_decimal: true,
	digits_after_decimal: [2],
	allow_space_after_digits: false,
}
```

Value: `R$ 1.400,00`

```
"statusCode": 400,
    "message": [
        "monthyMoneyGoal must be a currency"
    ],
    "error": "Bad Request"
```

But changing symbol to `$` it works:

```json
{
	symbol: '$',
	require_symbol: true,
	allow_space_after_symbol: true,
	symbol_after_digits: false,
	...
}
```

Value: `$ 1.400,00`

```
"statusCode": 200,
    "message": [
        "Successful update"
    ],
```

Changing symbol to `$R` it unbelievably too works! 

Why? Where is error?

PS: My app uses single quotes in Prettier Formatter




Pull request description:
Fix: isCurrency symbol validator regex
Some of the currency symbols starts with letters. For example: 
- Brazil Real R$
- Dominican Republic Peso RD$ 

For those cases, the RegExp pattern created to validate the currency simbol is not valid: 


Generated regex: 
```
 -?(\R$) ?(0|[1-9]\d*|[1-9]\d{0,2}(\,\d{3})*)?(\.(\d{2}))?
```
Expected regex:
```
-?(R\$) ?(0|[1-9]\d*|[1-9]\d{0,2}(\.\d{3})*)?(\,(\d{2}))?
```

Resolves #1292

Patch:
diff --git a/src/lib/isCurrency.js b/src/lib/isCurrency.js
old mode 100644
new mode 100755
index 8cea9fb..54b1f7c
--- 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})*`,


Test patch:
diff --git a/test/validators.js b/test/validators.js
old mode 100644
new mode 100755
index 76672ce..eeeb3c9
--- 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', () => {