Masked Text / Regex Input
Overview
Use the masked input component to prompt the user to enter a value that follows a strict format. This format typically includes two or more regions of characters and/or numbers, separated by a delimiter character such as hyphens, periods, and @ signs.
Valid values for each of these masked text inputs can be represented as a regular expression.
Examples of masked text include…
Type of Input | Example | Possible Regular Expression |
---|---|---|
Email addresses | john.smith@gmail.com | / ^((?!\.)[\w-_.]*[^.])(@\w+)(\.\w+(\.\w+)?[^.\W])$ / gm |
US phone numbers | 404-887-2931 | / ^(1\s?)?(\d{3}|\(\d{3}\))[\s\-]?\d{3}[\s\-]?\d{4}$ / gm |
US ZIP code format | 15632+1209 | / \d{5}(?:-?\d{4})? / i |
Tax identification numbers | 526-79-0835 | / ^((?!666|000)[0-8][0-9\_]{2}\-(?!00)[0-9\_]{2}\-(?!0000)[0-9\_]{4})*$ / gm |
Development
Web component development
Component reference
p-inputmask
Allows user to edit values that have a particular format
View the p-inputmask reference doc
If you're adding PrimeNG to your solution for the first time, reference their setup documentation. It's important to note that the inclusion of the nova-light theme css is not necessary to work with Responsive UI. Styling for the PrimeNG components is provided by Responsive UI's theming.
Implementation
Start by importing the InputMaskModule
from PrimeNG.
Then insert a p-inputMask
component in place of a typical input, supply a mask
and add the rui-form-control
class. View the different mask options and properties in the PrimeNG documentation. When storing only the value (without the mask characters), set unmask
to true.
Mobile-friendly masked text experience
You will need to use 2 elements in order to create a mobile-friendly input experience.
When you have an input where the only characters entered are numbers, but you want to display other characters in the mask (SSN, phone number, zip code), the type
in p-inputMask
will need to be text
. This will show the full keyboard on mobile devices instead of the number keypad.
In order to keep the correct keyboard in mobile and display a mask in the desktop view, you will use a p-inputMask
with the rui-hidden-mobile-device
class for the desktop and tablet experience, and a standard <input>
element with the type
set to number
and the rui-visible-mobile-device
class for the mobile experience.
Some types of masked values like telephone numbers and e-mail addresses have HTML5 input types tel
and email
to display the proper mobile keyboard.
Angular component development
Component reference
p-inputmask
Allows user to edit values that have a particular format
View the p-inputmask reference doc
If you're adding PrimeNG to your solution for the first time, reference their setup documentation. It's important to note that the inclusion of the nova-light theme css is not necessary to work with Responsive UI. Styling for the PrimeNG components is provided by Responsive UI's theming.
Implementation
Start by importing the InputMaskModule
from PrimeNG.
Then insert a p-inputMask
component in place of a typical input, supply a mask
and add the form-control
class. View the different mask options and properties in the PrimeNG documentation. When storing only the value (without the mask characters), set unmask
to true.
Mobile-friendly masked text experience
You will need to use 2 elements in order to create a mobile-friendly input experience.
When you have an input where the only characters entered are numbers, but you want to display other characters in the mask (SSN, phone number, zip code), the type
in p-inputMask
will need to be text
. This will show the full keyboard on mobile devices instead of the number keypad.
In order to keep the correct keyboard in mobile and display a mask in the desktop view, you will use a p-inputMask
with the jha-hidden-mobile-device
class for the desktop and tablet experience, and a standard <input>
element with the type
set to number
and the jha-visible-mobile-device
class for the mobile experience.
Some types of masked values like telephone numbers and e-mail addresses have HTML5 input types tel
and email
to display the proper mobile keyboard.
Design
Figma design
Dev Component | Design Component Name |
---|---|
Masked text input | JHA / Forms / Text Input; set State to “Watermark” if you want to show watermark text instead of user input, otherwise leave State as “Normal” |
Adobe XD design
- Sample App - Editing Form Data
Dev Component | Design Component Name |
---|---|
Masked text input | JHA / Forms / Text Input
|