# Registration: validate characters in username

**URL:** <https://forum.keycloak.org/t/registration-validate-characters-in-username/15472>\
**Category:** Getting advice\
**Created:** [May 11, 2022, 10:25am UTC](https://forum.keycloak.org/t/registration-validate-characters-in-username/15472 "2022-05-11T10:25:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![acidsys](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@acidsys](https://forum.keycloak.org/u/acidsys)\
**Post date:** [May 11, 2022, 10:25am UTC](https://forum.keycloak.org/t/registration-validate-characters-in-username/15472/1 "2022-05-11T10:25:04Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [May 11, 2022, 10:40am UTC](https://forum.keycloak.org/t/registration-validate-characters-in-username/15472/2 "2022-05-11T10:40:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![acidsys](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@acidsys](https://forum.keycloak.org/u/acidsys)\
**Post date:** [May 11, 2022, 10:50am UTC](https://forum.keycloak.org/t/registration-validate-characters-in-username/15472/3 "2022-05-11T10:50:16Z")

</div>

Thanks for the input! I found [this draft](https://github.com/keycloak/keycloak-community/blob/main/design/user-profile.md) about it, and a stalled [issue](https://issues.redhat.com/browse/KEYCLOAK-18418), but no reference as to where the preview can be acquired and/or enabled - could you point me to it?

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [May 11, 2022, 11:10am UTC](https://forum.keycloak.org/t/registration-validate-characters-in-username/15472/4 "2022-05-11T11:10:28Z")

</div>

Here [Server Administration Guide](https://www.keycloak.org/docs/latest/server_admin/#user-profile)

---

<div class="post-metadata">

**Author:** ![acidsys](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@acidsys](https://forum.keycloak.org/u/acidsys)\
**Post date:** [May 11, 2022, 11:47am UTC](https://forum.keycloak.org/t/registration-validate-characters-in-username/15472/5 "2022-05-11T11:47:14Z")

</div>

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