Reputation: 929
This is a more region specific question. I am developing an application for India in asp.net mvc3.
I have a field which takes decimal values. The jQuery validation fails for this field if the numbers as entered in the Indian format.
Example: Jquery works fine if I enter:
500000.12
or
500,000.12
But fails when this is written in the Indian format i.e.
5,00,000.12 // Fails with error - This is not a number.
In Indian format,
5,000 = 5,000
50,000 = 50,000
500,000 = 5,00,000
5,000,000 = 50,00,000
50,000,000 = 5,00,00,000
What should I do to ensure that jQuery validation does not fail for numeric fields?
I found the solution here: MVC 3 jQuery Validation/globalizing of number/decimal field
Upvotes: 1
Views: 1753
Reputation: 929
I found the answer in jQuery Globalization plugin from Microsoft
<script src="@Url.Content("~/Scripts/jquery.globalize/globalize.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.globalize/cultures/globalize.culture.hi-IN.js")" type="text/javascript"></script>
<script type="text/javascript">
$.validator.methods.number = function (value, element) {
return !isNaN(Globalize.parseFloat(value));
}
$(document).ready(function () {
Globalize.culture('hi-IN');
});
</script>
This is based on MVC 3 jQuery Validation/globalizing of number/decimal field
Upvotes: 1