// trim leading and trailing spaces from a stringfunction trim( txt ){    return txt.replace(/^\s+/, "").replace(/\s+$/, "");}// handle 99% of all email addressesfunction validateEmail( fld ){    var emRegex = /^([a-z][\w\-\'\.]+)+\@([a-z][\w\-\']*\.)+[a-z]{2,6}$/    var chk = emRegex.test( trim(fld.value) );    fld.style.borderColor = chk ? "transparent" : "red";    return chk;}// allow most any text, for minimum size:function minText( fld, minc ){    var chk = trim(fld.value).length >= minc;    fld.style.borderColor = chk ? "transparent" : "red";    return chk;}// could add other functions for other kinds of validation// now main form validation:function validateForm( form ){    var v = minText( form.name, 3 )          & validateEmail( form.email )          & minText( form.message, 10 );    return v != 0;}
