Click here to Skip to main content
15,348,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using the jQuery.validator.addClassRules method to validate my input fields for numbers. How do I allow my textbox to accept only comma seperated numbers (0,00) and show the default message if incorrect. Incorrect decimal numbers are:


What I have tried:

<pre><input type="text" class="form-control numberValidation" />

<!-- JS Plugins Init. -->
        function () {


            errorClass: 'invalid-input'            


            number: true
Updated 16-Dec-20 19:30pm

1 solution

I'm not sure about JavaScript - I see a number of possibilities

1) (short sighted) .. check if the string representing the number has a '.' in it, ie string.contains('.') sort of thing and reject if found .. it's not a great solution in that it's not flexible

2) validate using a regular expression - allowing '0'-'9' and '.' - this can be changed later if needed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900