Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

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

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 the user name is available in the system, and I want to make this ajax call only if the userName value is a valid one as per the rules set in $(form).validate();

I want something like:

$("#userName").keyup(function () {
    if ($("#userName").isValid()) {
        //make ajax called
    }
});

I searched the documentation but i couldn't identify the solution to my problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$("#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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...