10

I have the registration process working so that the custom attribute of "phone" is being stored when the user clicks register, if the user typed a phone number in that is. However, I would like it to be a required field and prevent registration from occurring if left blank. I have not found any keycloak documentation about how to do this.

user1869407
  • 227
  • 3
  • 19

1 Answers1

3

You have to implement a SPI that extend the registration form. You can use standard FormAction as base. You will have to add you validation logic to validate() method. For instance:

String phoneNumber = formData.getFirst(FIELD_PHONE_NUMBER);
if (Validation.isBlank(phoneNumber) {
  errors.add(new FormMessage(FIELD_PHONE_NUMBER, MISSING_PHONE_NUMBER));
}
Yeray Rodriguez
  • 307
  • 5
  • 14