Class-validator: IsCurrency symbol validation error

Created on 30 Apr 2020  路  5Comments  路  Source: typestack/class-validator

Hi devs,

I'm trying use BRL currency in @IsCurrency options, but when I use this setting the validator fails:

{
    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:

{
    symbol: 'R$',
    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

validator.js fix

Most helpful comment

@btd1337 now we have to update validato.js :) I will try release new version with updated dependencies soon.

All 5 comments

Doesnt look like class-validator problem. We use validatorjs isCurrency function. You have to create issue here - https://github.com/validatorjs/validator.js

Thank you! Lets see what validator.js maintainers will says.

@vlapo Fixed in: https://github.com/validatorjs/validator.js/pull/1306

What is the next step?

@btd1337 now we have to update validato.js :) I will try release new version with updated dependencies soon.

Was this page helpful?
0 / 5 - 0 ratings