I have used http://bassistance.de/jquery-plugins/jquery-plugin-validation/
my form validate :
$(\"#form_person\").validate({
rules: {
u
I just add the onfocusout event and its automatically Trim all the form fields and also if the user will enter only spaces (white-spaces) it will remove them and will show the field required message:
onfocusout: function (element, event) {
//Get Objects
$element = $(element);
//Remove whitespace
if ( $element.is(':input') && !$element.is(':password') ) {
$element.val($.trim($element.val()));
}
},
Its working also when the user submit the form directly because when he click the submit button the event is triggered.