JQuery Validator– Modyfing decimal separator

Problem

By default jQuery validator  uses only validation by “dot” separator.

default code:

I needed plugin that would allow “comma” separator.

Solutions

Simple or operator :

Combining two regexps. Not optimal but if you don’t know regexp its “good enough”.

brute force version :

Simple but effective version with string replace.

One regexp :

Best Solution ;]

Share on Facebook+1Share on Twitter
  • Last one

    In the “Best Solution”, where there’s .test(val); we should have .test(value);

    • http://www.mfranc.com/ Michal Franc

      Thanks for pointing this out :) Fixed.

  • Kristaps

    I think, the default code that you have shown searches for “comma” as a decimal seperator and “dot” as a thousand seperator.

    • http://www.mfranc.com/ Michal Franc

      I think you are right. I wonder how does the code looks like in the new versions of JQuery. This post is 3 years old ;)