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

前端 未结 16 706
野趣味
野趣味 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 17:13

    I've found that the majority of these are not quite what is needed.

    Using the following only fires on form change rather than on key down allowing you to still check on key stroke for the rest of the validation.

    It's not as tidy as including it within the plugin, but it's an acceptable compromise.

    $('body').on 'change', 'form input[type=text], form input[type=email]',  ->
        $(@).val $.trim($(@).val())
    

提交回复
热议问题