1$("form").submit(function(){ return validateForm($(this)) });
2function validateForm(form){
3var retVal = true;
4var re;
5$.each(form.serializeArray(), function(i, field) {
6 var input = $('input[name='+field.name+']');
7 field.value = $.trim(field.value);
8 switch(field.name){
9 case "name" :
10 and another cases...
11 }
12 })
13 }