Now I use the following:
1) Attaching this (stolen) code somewhere after loading jqueryval, etc. (and the presence of the files to which they refer) will have a culture applied to globalization at the bottom of this code, as a reference for checking input:
<script type="text/javascript" src="~/Scripts/jquery.globalize/globalize.js"></script> <script type="text/javascript" src="~/Scripts/jquery.globalize/cultures/globalize.culture.de-DE.js"></script> <script type="text/javascript"> (function ($, Globalize) { // Tell the validator that we want numbers parsed using Globalize $.validator.methods.number = function (value, element) { var val = Globalize.parseFloat(value); return this.optional(element) || ($.isNumeric(val)); }; $.validator.methods.min = function (value, element, param) { var val = Globalize.parseFloat(value); return this.optional(element) || val >= param; }; $.validator.methods.max = function (value, element, param) { var val = Globalize.parseFloat(value); return this.optional(element) || val <= param; }; $.validator.methods.range = function (value, element, param) { var val = Globalize.parseFloat(value); return this.optional(element) || (val >= param[0] && val <= param[1]); }; // Tell the validator that we want dates parsed using Globalize $.validator.methods.date = function (value, element) { var val = Globalize.parseDate(value); return this.optional(element) || (val); }; }(jQuery, Globalize)); $(document).ready(function () { // Set Globalize to german Globalize.culture("de-DE"); }); </script>
2) A custom error message if the value entered in the field violates the check or the user tries to send with an empty value for this field:
@Html.ValidationMessageFor(model => model.Datum, "my custom error message")
This is pitti, I know that I am noob, but it should be more intuitive to check server and client validation on a different culture, including all error messages.
peter source share