gauravmunjal
gauravmunjal

Reputation: 209

How to check whether a value already exists using AJAX in jQuery validator?

$.validator.addMethod("noanon", function(value) {
return ajaxFunction();
}, 'Username already exists.');

The addMethod function takes 3 arguments. A name, the logic to actually run, and lastly, the default message to use for failures.

name: {
 required: true,
 minlength: 2,
 noanon: true
},

Now if I use the ajaxFunction, there sems to be some error which is appearing.

Upvotes: 0

Views: 447

Answers (1)

Kir
Kir

Reputation: 694

You can use remote method:

rules: {
    name: {
        remote : "script.php"
    }
},
messages: {
    name: {
        remote : "Page with this name is exists"
    }
}

In PHP you take $_GET['name'].

Additional information here

Upvotes: 1

Related Questions