/
You can set mask expression using mask
parameter of MaskitoOptions
.
The most basic and comprehensible type. The only required knowledge is understanding of native JavaScript Regular expression .
See the following example:
For example, imagine that you have to create mask for 4-digits PIN code.
/^\d{4}$/
is a wrong mask expression. It does not match intermediate states (you cannot complete 4-digit string without possibility to type 1-, 2- or 3-digit string).
/^\d{0,4}$/
is the right solution for our example.
It is a good choice for more complex masks that are fixed in size. This type of mask expression is presented as array. Each element in the array has to be either a string or a regular expression. Each string is a fixed character and each regular expression is validator of character at the same index.
For example, imagine that you have to create mask for a time-string with HH:MM
format. It consists of 4 digits and 1 fixed-character separator :
.
This mask expression forbids anything excepts digits and limits length of the value to 5 characters.
Also, it manages user interactions with fixed character.
For example, user can just type four digits 1159
and the value becomes 11:59
Another example, if caret position is after the colon and user presses Backspace , the input's value will not change but caret will be moved to the left of the colon.
mask
parameter can also accepts function which generates mask expression. This function will be called every time before input changes to generate a new version of mask expression.
Think about optimization and memoization of the such function.
The following sections are recommended to explore core concepts further: