function trim(str) { var newstr = str.replace(/^\s*(.+?)\s*$/, "$1"); if (newstr == " ") { return ""; } return newstr; } function drop_spaces(str) { var newstr = trim(str); return newstr.replace(/\s+/g, ""); } function check_email(email) { var template = /^[A-Za-z0-9](([_.-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([.-]?[a-zA-Z0-9]+)*)\.([a-z].{1,10})$/; email = drop_spaces(email); if (template.test(email)) { return true; } return false; }