jquery.validate plugin - how to trim values before form validation

前端 未结 16 687
野趣味
野趣味 2020-12-04 16:12

I\'m using the excellent jquery.validation plugin by Jörn Zaefferer and I was wondering whether there\'s a easy way to automatically trim form elements before they are valid

16条回答
  •  天命终不由人
    2020-12-04 16:57

    I did this with success.

    Instead of:

    Email: { required: true, email: true }
    

    I did this:

    Email: {
        required: {
            depends:function(){
                $(this).val($.trim($(this).val()));
                return true;
            }
        },
        email: true
    }
    

提交回复
热议问题