OpenMRS registrationapp TextFieldWidget Regex Config & custom validation error message

I need to add a site specific regex to phone number field in the registration app for validation when registering a patient. Currently, Is there a way to pass the “regex” in the config?

Would adding an attribute “regex” with accessor and modifier to the TextFieldWidget class be acceptable?

The current error message when a regex validation in “uicommons” fails is “Invalid”. Is there a config value I need to pass to customize this error message?


@alaboso I think i previously encountered this error as well while creating my registration form but i later settle for this below:

{ “legend”: “”, “id”: “phoneNumberLabel”, “fields”: [ { “type”: “personAttribute”, “label”: “”, “formFieldName”: “phoneNumber”, “uuid”: “14d4f066-15f5-102d-96e4-000c29c2a5d7”, “widget”: { “providerName”: “uicommons”, “fragmentId”: “field/text” }, “cssClasses”: [“phone”] }] } ]

Did you try something like this?


Yes I did but in our scenario we are creating the Section, Question and Field programmatically in code. The Widget in this case is TextFieldWidget which has an inner class Config. This inner class has only size attribute, no regex. The superclass doesn’t have a regex attribute so how can this be added programmatically? (Is it acceptable to add regex attribute to class TextFieldWidget.Config?)

Is there also a way in the current implementation to pass a custom regex field validation error as users would not understand what “Invalid” means?

+1 to adding a regex attribute to the TextFieldWidget.config… I don’t think there are any drawbacks to that.

Take care, Mark