Posts Tagged ‘valdate’

jquery validate plugin with ajax duplicate check

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.

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;
});