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