jquery form validate not allow space for field non required field
i have tried this but is not working
$(document).ready(function(){
jQuery.validator.addMethod("noSpace", function(value, element) {
return value.indexOf(" ") < 0 && value != "";
}, "No space please and don't leave it empty");
$("form").validate({
rules: {
name: {
noSpace: true
}
}
});
})
You can use this much of code.