Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hey guys, I'm just wondering if anyone knows why the Jquery Validation is only working when the required attribute is set to true? So basically all I want to do is check that the user entered a number in to the field on screen before submitting the from.

Generated Html from my helper.
HTML
<div class="form-group">
   <label class="control-label col-lg-4" for="MaxUploadSpeed">Max Upload Speed</label>
<div class="col-lg-8">
   <input class="form-control" data-val="true" data-val-number="The field Max   Upload Speed must be a number." id="MaxUploadSpeed" name="MaxUploadSpeed" type="number" value="" />
</div>
</div>


Jquery Validation code
JavaScript
  $('#block-validate').validate({
        rules: {

        number: {
                required : false,
                number: true 
        },
        date :{
            required :true
        }
});


All this works fine when the required is set to true so I'm just wondering if anyone knows what I'm doing wrong here. Thanks in advance guys.
Posted
Comments
arvind mepani 11-Jul-14 7:23am    
number validation using jquery validate apply couldn't apply for white space or empty textbox.
frostcox 11-Jul-14 10:17am    
Hey when I enter text in the numeric field it allows the form to be submitted. Any ideas?

1 solution

You have used type number in jquery validation instead of ID of the input tag
so need to change number with ID of control as MaxUploadSpeed and you missed "}" in your jquery validation code I have fix code and as below
C#
$('#block-validate').validate({
               rules: {

               MaxUploadSpeed: {
                       required : false,
                       number: true
               },
               date :{
                   required :true
               }
               }});



For Love demo you can see here :
http://jsfiddle.net/anomepani/MuV4J/3/[^]
 
Share this answer
 
v2

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