jquery form validate not allow space for username field?

后端 未结 7 1217
别那么骄傲
别那么骄傲 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条回答
  •  忘掉有多难
    2020-12-17 15:17

    I just add the onfocusout event and its automatically Trim all the form fields and also if the user will enter only spaces (white-spaces) it will remove them and will show the field required message:

    onfocusout: function (element, event) {
    
        //Get Objects
        $element = $(element);
    
        //Remove whitespace
        if ( $element.is(':input') && !$element.is(':password') ) {
            $element.val($.trim($element.val()));
        }
    },
    

    Its working also when the user submit the form directly because when he click the submit button the event is triggered.

提交回复
热议问题