Java Regular Expressions for Masks
Masks are defined using Java Regular Expressions. The internet provides many tutorials on the use of regular expressions. A regular expression tester is available at http://www.regular-expressions.info/javascriptexample.html and can be used to test the regular expressions configured for masks.
Below are several examples of regular expressions used to define masks.
Mask Name | Input Format | Output Format | User Input | Masked Output |
---|---|---|---|---|
Password |
|
($1)*** |
ppp |
(ppp)*** |
PhoneNumber |
|
0 91 ($1) $2 $3 |
1112223333 |
0 91 (111) 222 3333 |
USPhoneNumber |
|
($1)-($2)-($3) |
1112223333 |
(111)-(222)-(3333) |
USPhoneNumber2 |
|
($3)-($2)-($3) |
1112223333 |
(3333)-(222)-(3333) |
USPhoneNumber 3 |
|
*$2* |
1112223333 |
*222* |
Input expressions serve two purposes:
- Provide validation pattern for the user input.
- Provide character groupings that are used for replacement/formatting in the output.
Output expressions format and/or perform string replacement according to the groupings indicated by the input expression. Groups are formed by using () in the input expression. The captured groups are represented by $1, $2, and so forth. These groups can be used in any combination/permutation to obtain the required output.