Announcing: Regex Config Input Validation

Mariel Wilding
 | 
May 3, 2023
regex config title

Misconfigurations are frustrating and can cause problems and negatively impact the user experience if they go unnoticed. The new config input validation capability allows vendors to define guardrails using regular expressions to ensure values provided by an end user are valid. On KOTS version 1.98.0+, regular expressions can now be used to validate users’ input for [.inline] text [.inline], [.inline] textera [.inline], [.inline] password [.inline], and [.inline] file [.inline]config option types. Config input that doesn’t match the provided regular expression will be rejected so that users cannot save the config and proceed with the installation. This prevents users from deploying an application with a configuration that is verifiably invalid, thereby increasing installation success rates and improving the user experience. 

Previously, preflight checks could be used to validate config options, such as password length or email address validity. However, running these validation checks in preflights also makes it more difficult for users to correct their mistakes due to needing to navigate back to the config screen to make adjustments, save the config, and re-run preflights. While this is still an option, simple validations of this nature should fail fast and inform a user that their config input is malformed much sooner than when preflight checks run.

Allowing vendors to use regular expressions to validate config input directly on the config page gives end users immediate feedback on their input and lets them adjust accordingly while still in the config workflow.

How does it work?

Vendors can define a regular expression for one or more items in their config. This regular expression is used to validate input for that config option. This can be configured as:

[.pre] spec:
     groups:
          - name: guestbook_settings
             title: Guestbook Config
             items:
               - name: email_address
                  title: Email address
                  type: text
                 validation:
                        regex:
                             pattern: ^(?P<name>[a-zA-Z0-9.!#$%&'*+/=?^_ \x60{|}~-]+)@(?P<domain>[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$
                             message: You must enter a valid email address! [.pre]

The key field is [.inline] validation.regex [.inline] and its subfields.

  • [.inline] pattern [.inline] - This field indicates the regular expression to use for validation.
  • [.inline] message [.inline] - This field defines a failure message that will display if the config input is invalid.

When entering config from the admin console, invalid config input will be highlighted in red and the vendor-supplied error message will display to guide users toward entering a valid input. Invalid items will also be highlighted in red in the config nav to help users easily locate and fix them. The config cannot be saved until all config items pass validation.

When installing from the CLI and passing a [.inline] ConfigValues [.inline] file, invalid config input will block the installation and the vendor-supplied message will be displayed in the terminal. This is done both on the initial install (with [.inline] kots install [.inline]) and when changing the config using [.inline] kots set config [.inline].

For more information, see our documentation on config input validation.

Learn More

Want to learn more about these new features and what Replicated does to help vendors and customers install and manage modern apps on-prem? We would love to show you -- click here to schedule a demo.