jquery form validate not allow space for username field?

后端 未结 7 1205
别那么骄傲
别那么骄傲 2020-12-17 14:43

I have used http://bassistance.de/jquery-plugins/jquery-plugin-validation/

my form validate :

$(\"#form_person\").validate({
    rules: {


        u         


        
7条回答
  •  猫巷女王i
    2020-12-17 14:53

    I used the answer of @Reigel but it didn't work for me.

    I have change his example like this :

      $(document).ready(function(){
    
        jQuery.validator.addMethod("noSpace", function(value, element) { 
          return value == '' || value.trim().length != 0;  
        }, "No space please and don't leave it empty");
    
    
        $("form").validate({
           rules: {
              name: {
                  noSpace: true
              }
           }
        });
    
    
      })
    

    In my opinion noSpace isn't responsible to verify empty TextBox(Input). It is responsible to check value if some things was entered.

    And it will be a good idea if you use jQuery.validator.addMethod... in other JS file and add this JS file to your master page or some things like that.

提交回复
热议问题