Skip navigation

Tag Archives: valdate

jQuery validate plugin is pretty awsome. However it doesn’t do everything. That’s why the plugin have the addMethod function. And I need to add an ajax duplicate check for an email input. Here’s the method i wrote. There might be a better way. I would love to know.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
jQuery.validator.addMethod("checkForDupeEmail", function(value, element, param){

var ajaxFunc = $.ajax({
async:false,   //we have to set it to false, it does not return a value before we even complete the request.

data:'email='+($.trim(value)),
type:'POST',
url:'/employees/ajax_checkDupe',
dataType:'text',
});

//here we check the response


if(ajaxFunc.responseText == 1)
return true;
else
return false;
});