jQuery Validation plugin: how to check if an element is valid?

后端 未结 4 2022
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 06:15

A little bit of context:

I\'m using the jQuery Validation plugin to validate a sign-up form. I now want to implement an ajax call to check whether t

相关标签:
4条回答
  • 2020-12-15 06:31

    This worked for me on JQuery 1.11

    $("#userName").keyup(function () {
        if ($(this)[0].validity.valid) {
            // AJAX here
        }
    });
    
    0 讨论(0)
  • 2020-12-15 06:35

    Validator.element()

    Description: Validates a single element, returns true if it is valid, false otherwise.

    http://jqueryvalidation.org/Validator.element

    0 讨论(0)
  • 2020-12-15 06:35

    Hello i find exclusive solution, i have the same problem as 47k others & i discover the solution without other jquery plugins or libraries: -first of all we need to register our input in a variable, -then on change checkValidity() if true:mean if valid we assign the registered var to our input to rest it for next change.

            ivar=$('input[name="y-i-name"]')[0];
            $('input[name="y-i-name"]').on('change',function(){
                 if($('input[name="y-i-name"]')[0].checkValidity()){
    
    
                         // your custom code here!
    
    
    
                         $('input[name="y-i-name"]')[0]=ivar; // & now we rest the input for next change validation
                 }
            });
    
    0 讨论(0)
  • 2020-12-15 06:54
    $("#userName").keyup(function () {
        if ($("#userName").valid() == true ) {
            //make ajax called
        }
    });
    

    http://docs.jquery.com/Plugins/Validation/valid

    Note: To those who do not click the link. You have to call $("#myform").validate(); first.

    0 讨论(0)
提交回复
热议问题