Skip to main content

Overview

HasAllowedCharPatternElement provides utilities to interact with Vaadin input components that support the allowedCharPattern property. This property constrains which characters users can type into the field by specifying a regular expression pattern. This mixin interface extends HasLocatorElement and provides default implementations for getting, setting, and asserting the allowed character pattern.

Interface

Methods

getAllowedCharPattern()

Retrieves the current allowedCharPattern from the component.
Returns: The pattern string, or null if no pattern is set Implementation:

setAllowedCharPattern()

Sets the allowedCharPattern on the component programmatically.
String
Regular expression pattern to apply. For example, "[0-9]" allows only digits, "[A-Za-z]" allows only letters.
Implementation:

assertAllowedCharPattern()

Asserts that the allowedCharPattern matches the expected value.
String
Expected pattern string. If null, asserts that no pattern is set.
Behavior:
  • If pattern is non-null: Asserts the component has exactly that pattern
  • If pattern is null: Asserts the attribute is absent

Implementing Classes

The following element classes implement HasAllowedCharPatternElement:
  • TextFieldElement - Text input fields
  • BigDecimalFieldElement - Decimal number fields
  • AbstractNumberFieldElement - Base class for number fields
  • ComboBoxElement - Combo box selectors (with text input)
  • MultiSelectComboBoxElement - Multi-select combo boxes

Usage Examples

Restricting Input to Digits

Restricting Input to Letters

Testing Pattern Validation

ComboBox with Pattern

Programmatic Pattern Changes

Common Patterns

Here are some commonly used character patterns:

Important Notes

  • The pattern is applied per character as the user types
  • Characters that don’t match the pattern are silently ignored
  • The pattern does not validate the entire value, only individual characters
  • For full value validation, use Vaadin’s validator mechanisms in addition to allowedCharPattern
  • The pattern uses JavaScript regex syntax (same as HTML5 pattern attribute)

Vaadin Documentation

For more information about the allowedCharPattern property, see: