2

I want to set jQuery validation to consider as valid decimal point and not comma (0.5 <- not valid, 0,5 <- valid). How can I achieve this?

Edit:

I use ASP.NET MVC 4 form:

I have some field with float type in model.

I have for these fields Html helper editors.

 @Html.EditorFor(model => model.OverRunningClutch.D2)

The framework automatically do a lot of things (like client side validation with jquery validation). But the ASP.NET DefaultModelBinder does not parse the fields in the format that has the decimal point. But if I type with comma, the jquery validation say it is not valid.

dvjanm
  • 2,351
  • 1
  • 28
  • 42

1 Answers1

0

The long, complete and really interesting answer is in Globalization, Validation and Date/Number Formats in Asp.Net MVC

For a Q&D short answer, you may go for something like :

var genuineNumberFunc = $.validator.methods.number;
$.validator.methods.number = function (value, element) {
 if(value.indexOf(',')!=-1)
      return false;
 return genuineNumberFunc(value, element);
}
jbl
  • 15,179
  • 3
  • 34
  • 101