diff --git a/src/register/RegistrationFields/UsernameField/UsernameField.jsx b/src/register/RegistrationFields/UsernameField/UsernameField.jsx index 59d077c62b..97e9e5ac21 100644 --- a/src/register/RegistrationFields/UsernameField/UsernameField.jsx +++ b/src/register/RegistrationFields/UsernameField/UsernameField.jsx @@ -100,27 +100,30 @@ const UsernameField = (props) => { dispatch(clearUsernameSuggestions()); }; - const suggestedUsernames = () => ( -
- {formatMessage(messages['registration.username.suggestion.label'])} -
- {usernameSuggestions.map((username, index) => ( - - ))} -
- {iconButton} -
- ); +const suggestedUsernames = () => { + const validSuggestions = usernameSuggestions.filter(username => usernameRegex.test(username)); // Filter valid suggestions + return ( +
+ {formatMessage(messages['registration.username.suggestion.label'])} +
+ {validSuggestions.map((username, index) => ( + + ))} +
+ {iconButton} +
+ ); +}; if (usernameSuggestions.length > 0 && errorMessage && value === ' ') { className = 'username-suggestions__error';