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 currentallowedCharPattern from the component.
null if no pattern is set
Implementation:
setAllowedCharPattern()
Sets theallowedCharPattern on the component programmatically.
String
Regular expression pattern to apply. For example,
"[0-9]" allows only digits, "[A-Za-z]" allows only letters.assertAllowedCharPattern()
Asserts that theallowedCharPattern matches the expected value.
String
Expected pattern string. If
null, asserts that no pattern is set.- If
patternis non-null: Asserts the component has exactly that pattern - If
patternis null: Asserts the attribute is absent
Implementing Classes
The following element classes implementHasAllowedCharPatternElement:
TextFieldElement- Text input fieldsBigDecimalFieldElement- Decimal number fieldsAbstractNumberFieldElement- Base class for number fieldsComboBoxElement- 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)
Related Interfaces
- HasLocatorElement - Parent interface
- HasPrefixElement - For prefix slot content
- HasSuffixElement - For suffix slot content
Vaadin Documentation
For more information about theallowedCharPattern property, see: