Allow dot and comma in numbers, not just decimals

I have a localization problem. In Brazil, we use a comma as a decimal separator instead of a period. For instance:

500,00 120,21 0,0001 

I found a solution to this problem based on this answer: MVC 3 jQuery Check / Globalize Number / Decimal Field

But here in Brazil, we also use ".". in numbers, for example:

 100.000.000,00 11.125,23 

One more thing:

 10.000 <> 10,000 

The first is ten thousand, and the second is ten.

Using the globalization plugin, when the user enters β€œ.”, It shows a validation error. I tried using DisplayFormat data annotation, but it did not work as expected ... To "solve" these problems, I use javascript to install and uninstall manually. from the numbers on the field, but this is very problematic when we need to change something (and I'm sure this is one of the worst approaches that I could use ...). Do you guys know how to act in this case?

One more question: can I create a model binding (or modify an existing one) to accept this number format?

+6
source share
1 answer

I just found this answer.

Fixing decimal places

In my script, it worked great. This guy solved the same problem as me!

I just changed a few lines of code, but the most important part was this line:

 ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder()); 

I modified it to accept values ​​with a null value.

+10
source

Source: https://habr.com/ru/post/956003/


All Articles