1

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

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Tripping
  • 919
  • 4
  • 18
  • 36
  • Can you tell us more about the Indian format? Like in general for even bigger number, if possible. – nhahtdh Dec 27 '12 at 13:16
  • http://stackoverflow.com/questions/8091373/locale-aware-number-conversion-in-javascript – user1824407 Dec 27 '12 at 13:18
  • 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 helps – Tripping Dec 27 '12 at 13:25
  • Are you applying any regex rules..? – Anujith Dec 27 '12 at 13:31
  • I have found a blog post .. will give this a try and let you know http://blog.brainnovative.com/2010/12/globalizing-aspnet-mvc-unobtrusive.html – Tripping Dec 27 '12 at 13:40
  • if you follow that link you will find a ready to use solution by the way ... don't ask for help if you don't want to read the responses . – user1824407 Dec 27 '12 at 14:02
  • The link you mentioned is to translate numerals ... my question was regarding validation. – Tripping Dec 27 '12 at 18:50
  • I found the solution in the jQuery Globalization plugin from Microsoft: http://stackoverflow.com/questions/5199835/mvc-3-jquery-validation-globalizing-of-number-decimal-field – Tripping Dec 27 '12 at 23:40

1 Answers1

1

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

Community
  • 1
  • 1
Tripping
  • 919
  • 4
  • 18
  • 36