MVC 3 client side validation, model binding decimal value and culture (different decimal separator)

后端 未结 3 1691
一向
一向 2020-12-14 03:45

I am trying to have my client side validation (model binding) to support different cultures, and I found an interesting blog on the subject on which I am trying to implement

3条回答
  •  时光说笑
    2020-12-14 04:40

    Finally, by understanding that the Custom DecimalModelBinder would only handle server-side validation and not affect the jquery.validate.js which handles the client-side validation, I found a solution to the problem.

    Extending the validation solved my issue.

    enter image description here

    Extend the validation by a new .js file as a workaround to the problem:

    $.validator.methods.number = function(value, element) {
      return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:[\s\.,]\d{3})+)(?:[\.,]\d+)?$/ .test(value);
    };
    

    This blog was really helpful http://rebuildall.umbraworks.net/2011/03/02/jQuery_validate_and_the_comma_decimal_separator

提交回复
热议问题