I am writing a jquery form validation plugin, its working fine. I am passing a form ID with its input types, something like this :
$('#contactForm :input').validateForm();
And inside my plugin I have following code :
jQuery(function($) {
$.fn.validateForm = function() {
var values = new Array();
this.each(function() {
$(this).removeClass('error');
if($(this).hasClass('required'))
{
if($(this).hasClass('number'))
{
number = $(this).val();
if(number == '' || number.length < 9 || number.length > 13 || isNaN(number))
{
$(this).addClass('error');
}
}else{
return true;
}
}
});
}
});
Now my problem is that I want my plugin to return a value as true or false. If the form is validated then it should return true or if not then false.
I want to achieve something like this
val = $('#contactForm :input').validateForm();
if(val){
//DO AJAX
}
How can I do that?
1 Answer