var email = " hogehoge@example.com  \n";
var localpart = "";
var domainpart = "";

email = email.trim();

var matches = email.match(/^(.*?)@(.+)$/);

if (matches && matches.length === 3) {
    localpart = matches[1];
    domainpart = matches[2];
}

alert("email=" + email + ", localpart=" + localpart + ", domainpart=" + domainpart);
