Click here to Skip to main content
14,717,158 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:

0.00
1.20
2.30

What I have tried:

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


<!-- JS Plugins Init. -->
<script>
    $(document).on('ready',
        function () {

            $("#signupform").validate({

            errorClass: 'invalid-input'            

        });

        jQuery.validator.addClassRules('numberValidation',
        {
            number: true
        });
    });
</script>
Posted
Updated 16-Dec-20 20:30pm
v2

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
欧美日韩亚洲中字二区_欧美日韩在线无码一区二区三区_欧美日韩无线码免费