You should check return value of this function "if (!normalizePlayerName(newName)) { do some error; return false; }