Configure globalize.js to use CLDR for validating decimal numbers

593 views Asked by At

I need to validate decimal numbers in the Serbian culture (a decimal separator is comma instead of a dot).

I am looking on the internet to find a solution and most posts suggest to use globalize.js. But I can set it up to work for me.

Here is code:

<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
<script src="~/lib/cldrjs/dist/cldr.js"></script>
<script src="~/lib/cldrjs/dist/cldr/event.js"></script>
<script src="~/lib/cldrjs/dist/cldr/supplemental.js"></script>
<script src="~/lib/globalize/dist/globalize.js"></script>
<script src="~/lib/globalize/dist/globalize/number.js"></script>

<script>
$.when(
  $.get("/lib/cldr-data/supplemental/likelySubtags.json"),
  $.get("/lib/cldr-data/main/sr/numbers.json"),
  $.get("/lib/cldr-data/supplemental/numberingSystems.json")
).then(function () {
  return [].slice.apply(arguments, [0]).map(function (result) {
    return result[0];
  });
}).then(Globalize.load).then(function () {
  Globalize.locale("sr");
});
</script>

This code is placed on the end of each page where I need validation. Of course, I load jQuery in the HEAD tag.

When I load the page into a browser, there is no error in the console, but the decimal separator is still a dot.

ASP.NET 5 MVC6 generated input tag is:

  <input class="form-control input-validation-error" type="text" data-val="true" data-val-number="The field Plaćanje must be a number." data-val-required="The Plaćanje field is required." id="Payment" name="Payment" value="0,00" aria-required="true" aria-invalid="true" aria-describedby="Payment-error">
0

There are 0 answers