Registration: validate characters in username

Hi,

by reading other posts here and the documentation I only found the following options to add validation to the username field:

  • Extending the theme (FTL or React) to perform a Regex pattern match on the field
  • Writing a custom module extending the built-in validation method

The first option does not sound ideal, as someone could likely just craft their own HTTP request and submit the registration without the rendered form.

The second option seems to be a bit overkill, as I wouldn’t only need to write the module, but additionally need to maintain it to keep working with future Keycloak updates.

Do I have any other options to add basic username validation to the registration process?
I do not need validation in other places (i.e. I don’t mind if administrators are allowed to add users with arbitrary characters in the backend), but want the registration process that is exposed to the end user to block usernames with a specified set of characters.

Thanks for any ideas!

The new declarative „User Profile SPI“ might be your friend. Search the docs for it, don‘t know exactly in which of the docs it is mentioned.
It‘s still a preview feature but works. It has to be enabled separately.

Thanks for the input! I found this draft about it, and a stalled issue, but no reference as to where the preview can be acquired and/or enabled - could you point me to it?

Here Server Administration Guide

1 Like

Ah, “Declarative User Profile” it’s called there. Thank you!