Class InputMask
Formats text as it is typed against a pattern: a phone number, a card expiry, a
postal code. In the pattern 9 stands for a digit, a for a letter, * for
a letter or a digit, and every other character is a literal the mask inserts itself.
A backslash makes the next character literal.
TextField phone = new TextField();
phone.setInputMask(new InputMask("(999) 999-9999"));
// typing 5551234567 shows (555) 123-4567; getText() answers the formatted text
String digits = phone.getInputMask().unmask(phone.getText()); // 5551234567
Characters that do not fit the next slot are dropped, and input past the end of the pattern is ignored. A mask is immutable and may be shared between fields.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFormats text against the mask.intThe length of fully formatted text.booleanisComplete(String formatted) Whether text fills every slot of the mask.Removes the literals of the mask, leaving what the user typed.
-
Constructor Details
-
InputMask
Creates a mask.
Parameters
pattern: the pattern, for example99/99or(999) 999-9999
-
-
Method Details
-
getLength
public int getLength()The length of fully formatted text.
Returns
the number of characters a complete entry has
-
apply
Formats text against the mask. Literals already present are recognised, so formatting formatted text answers it unchanged.
Parameters
text: raw or partly formatted text
Returns
the formatted text; it stops after the last character typed, so a literal is added only once the character after it arrives
-
unmask
-
isComplete
Whether text fills every slot of the mask.
Parameters
formatted: the text
Returns
true when the entry is complete
-