I am trying to use jQuery validation to validate an email input field against our database, to see if the email ID already exists.
The input field looks like this.
<input name='email' id='id_email'/>
The validation is done like this. I'm binding the remote rule later.
var validator = $('form').validate({
rules: { "email": {required:true,email:true} },
messages: { "email": {
required:'Please enter your email ID.',
email:'Please enter a valid email ID.',
remote: $.format('{0}')
}}
});
$('#id_email').rules('add', {
remote:{
url:'/validate/',
type:'post',
dataType:'text',
data:{'id_email':function() { return $('#id_email').val(); }}
}
});
Now the server would respond with the error message (some plain text) if validation failed, or nothing if validation passes through.
I'm able to display the error message from the server correctly when validation fails. However, when a valid email ID is entered and the server responds with an empty response, the error message shows the input field's value. How do I treat this as true validation and not display any error message?