The new Asp.net mvc 2.0 input validation works like a charm, except for decimal separators when it comes to jquery.validate. When I use the Microsoft MVC ajax libs it works fine. The comma is the decimal separator server side as well as client side.
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript" ></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript" ></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
When I use this (jquery is loaded in the master view), I have to use a dot on the client side. But then the model is invalid and it gets returned back to the view, creating an interesting loop.
<script src="/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcJqueryValidation.js" type="text/javascript"></script>
I'd rather use jquery for all my javascript needs, is there any way to make jquery.validate use the comma, and not the dot ? I have been googling and reading the docs, but weird enough I couldn't find much on this issue, which you would think would be a common one.
Ahhh... The joys of globalization!
When dealing with number (and I won't even get started on dates) the need to determine the right decimal separator can be daunting. However, there's an easy way to determine the decimal separator for any client:
function GetDecimalSeparator()
{
return (1 / 10).ToString().substring(1, 1);
}
This way you'll always know what's the decimal separator at the client, and have the validation performed accordingly.
Probably you will find the answer in the additional-methods.js. You will find the example of date localization: search for <input name="pippo" class="{dateITA:true}" />
and jQuery.validator.addMethod("dateITA",
which follows. You can do the same to add and use your custom validation of numbers (corresponds to the locale which you use).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With