Search code examples
jqueryunobtrusive-validation

jquery unobtrusive how to override validation method


I am trying to validate a number that not is required but the native method don't allow this.

There is a way to override the native method or I have to add a custom method?

Edit

<input class="form-control" data-val="true" data-val-number="The field Foo must be a number." id="Foo" name="Foo" type="text" value="">

Note: this is generated by asp.net mvc


Solution

  • this work for me

      $(function() {
            $.validator.methods.number = function (value, element) {
                return !value || Globalize.parseFloat(value).toString() != "NaN";
            }
      }