Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globalization decimal type client validation in mvc

I have an application that is multilingual. I have a simple model like this

public class Product
{
    public string Name { get; set; }
    public decimal Price{ get; set; }
}

I set CurrentCulture to a culture that has different decimal separator like French "fr-FR" (in french decimal separator is , ). In my Create Page when I put a number like 655,20 for price I got a javascript validation error that says:

The field Price must be a number.

When I change CurrentCulture to en-Us I can submit my form.

like image 201
M.Azad Avatar asked Dec 08 '25 07:12

M.Azad


1 Answers

You can use the Globalisation Nuget Package (globalize.js) which works with jQuery. Alternatively you can override the $.validator.methods.number method to allow an alternative decimal separator For an example refer this blog.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!