Currency PT-BR not working in Input Number
michelveloso opened this issue · comments
Describe the bug
I am using native-ui to format PT-BR (Brazil) currency.
However, even using a valid PT-BR format, even customizing the values by functions, the value is not accepted.
Steps to reproduce
-
access the codesandbox link (https://codesandbox.io/p/devbox/focused-edison-xwpmmw?file=%2Fsrc%2FApp.vue)
-
Enter a valid value in PT-BR, for example: 1.285,45 the field will have a risk informed that the value is not valid
-
Enter a valid value in PT-BR, for example: 55.500,38 the amount will not be accepted
Link to minimal reproduction
https://codesandbox.io/p/devbox/focused-edison-xwpmmw?file=%2Fsrc%2FApp.vue
System Info
"naive-ui": "^2.38.1"
"vue": "^3.4.21"
"vite": "^2.3.7",
Used Package Manager
yarn
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
It was actually a mistake on my part, I adjusted the function this way and it worked great!
const parseCurrency = (input: string) => {
const nums = input.replace(/\./g, '').replace(',', '.').trim();
if (/^\d+(\.\d+)?$/.test(nums))
return parseFloat(nums);
return nums === '' ? null : Number.NaN;
};