1
votes

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

1
Can you tell us more about the Indian format? Like in general for even bigger number, if possible.nhahtdh
nhahtdh - I have included some numbers in the original question. basically, the indian format puts a comma after every 2 zeros after 1 thousand. so 5,000 is same as 5,000 but 500,000 is 5,00,000 and any other big number would be .. 5,xx,xx,xx,xx,xx,xx,000. Hope that helpsTripping
Are you applying any regex rules..?Anujith
I have found a blog post .. will give this a try and let you know blog.brainnovative.com/2010/12/…Tripping

1 Answers

1
votes

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