String result = toSanitize;
//check for null input
if (result == null) {
throw new InvalidEmailAddressFormatException();
}
result = result.trim();
//check that the string is not too long
if (result.length() > 128) {
throw new InvalidEmailAddressFormatException();
}
//check to see if the string can be used for a username. If it can't
//throw an auth exception
if (!validateEmailAddress(result)) {
throw new InvalidEmailAddressFormatException();
}
result = result.toLowerCase();
return result;