mask([mask], [placeholder])
Class: TextField.
Description:
Sets or gets a text mask formatter with a specified mask string and a placeholder character.
A mask string defines the allowed characters at each position.
Each special character in the mask has a meaning:
#— A digit (0–9).U— An uppercase letter (A–Z).L— A lowercase letter (a–z).A— Any letter (A–Z or a–z).?— Any letter (case-insensitive).*— Any character (letter or digit).H— A hexadecimal character (0–9, A–F, a–f)..,,,:,-,/— These are treated as literal characters and appear in the formatted text.'(single quote) — Escape character. Place before a literal mask character if you don’t want it treated specially.
Example:"'#'###"means literal#followed by three digits.
Example masks:
"###-##-####"→ U.S. Social Security number (digits with dashes)."(###) ###-####"→ U.S. phone number."UUU-####"→ Three uppercase letters, dash, and four digits.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
|
|
string |
Text mask string. Set to empty string or |
|
|
|
string |
"_" |
A character to use for empty characters in the mask. Default is "_" character. |
Returns:
When setting a mask, returns this TextField component for chaining. When called without arguments, returns the current mask information object.
Type: Object | TextField
Examples:
// U.S. Phone number mask
textfield.mask("(###) ###-####", "_");
// Date input (MM/DD/YYYY)
textfield.mask("##/##/####", "_");
// Time input (HH:MM)
textfield.mask("##:##", "_");
// Product code input
textfield.mask("AAAA-####", "_");
// Get current mask settings
const info = textfield.mask();
console.log(info.mask, info.placeholder);
