Watch for @inject ... for Localization property
Install NuGet packages:
- jquery-globalize.0.1.3
- jquery.validation
- Microsoft.jQuery.Unobtrusive.Validation
Choose your culture and properly initialize globalize library:
<script src="~/Scripts/globalize.0.1.3/globalize.js"></script>
<script src="~/Scripts/globalize.0.1.3/cultures/globalize.culture.hr.js"></script>
<script>
$(document).ready(function () {
Globalize.culture("hr");
$.validator.methods.number = function (value, element) {
return this.optional(element) || !isNaN(Globalize.parseFloat(value));
}
$.validator.methods.range = function (value, element, param) {
return this.optional(element) || (Globalize.parseFloat(value) >= param[0] && Globalize.parseFloat(value) <= param[1]);
}
$.validator.methods.date = function (value, element) {
return this.optional(element) || Globalize.parseDate(value);
};
});
</script>
This handles check on client side on input values.
I haven't tried but for input validation there is DataFormatString param validation:
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? BirthDate { get; set; }
https://stackoverflow.com/questions/13916991/mvc-datatype-errormessage
No comments:
Post a Comment