If you want to globalize unobtrusive jQuery valdiation in your ASP.NET MVC3 the post by Phil Haack won't do the job for you. Still it's quite simple to do.
First of all you'll need to download jquery-glob and place globalization.js and Globalization.xx-XX.js in your Scripts folder. Then you need to include them after regular validation scripts. Below is an example of how it should look:
<script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"> </script> <script src="/Scripts/jquery.validate.min.js" type="text/javascript"> </script> <script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"> </script> <script src="/Scripts/globalization/globalization.js" type="text/javascript"> </script> <script src="/Scripts/globalization/Globalization.pl-PL.js" type="text/javascript"> </script>
In my case the globalization script is: Globalization.pl-PL.js since that's the locale of my customer and his web application.
After that if you want the validator to format the numbers correctly you'll need to add the following code to 'tell' the validator what function to use when validating number format:
After that if you want the validator to format the numbers correctly you'll need to add the following code to 'tell' the validator what function to use when validating number format:
<script type="text/javascript">
$.validator.methods.number = function (value, element) {
if (Globalization.parseFloat(value)) {
return true;
}
return false;
}
$(document).ready(function () {
$.culture = jQuery.cultures['pl-PL'];
$.preferCulture($.culture.name);
Globalization.preferCulture($.culture.name);
});
</script>
Now your validation client will pass when you input number like 12,90 (PL) instead of 12.90 (EN).
I noticed that you can't use the jQuery version of the Globalization plugin. There's a naming conflict between jQuery.validate.format and jQuery.glob.format.



