The RangeValidator will fetch the value of the input and validate it with regex. Part of the regex is the localized decimal character.
So, in the German culture the RangeValidator will fail if I enter 100.00, however it will accept 100,00, because , is the decimal character of the German culture.
On the new input[type=number] (asp:TextBox with TextMode="Number") of HTML5, I can enter 100,00 or 100.00 (with the stepattribute set to "0.01" and it will always hold the value 100.00. This will cause the RangeValidator to fail all the time in the German culture.
Changing the location to en-US would solve the problem, but I need the application in the users locale.
Can I, somehow, tell the RangeValidator to always use . as decimal character or are there any better ways to handle this situation?
So this is dirty but works:
I've overridden the
ValidatorValidatefunction of the framework:And now I can force specific JS variables on the validator by using data attributes. To force the
RangeValidatorto use theen-USlocale, I simply force it to setdecimalcharto.anddigitsto2from the ASPX markup:But, this is just dirty, it's not? ...
Please be aware of problems with UpdatePanels when overriding JS functions that involve the client validation mechanism, like this one.
What I'm really confused about is the fact this works, even when I'm only modifying the client side script. The server sided validation accepts the value from the English culture. This is really strange.