What is an input mask?
An input mask is like a face mask. A face mask covers the opening (mouth) that otherwise would allow bad things into the human body. An input mask is similar. It acts like a mask by preventing bad things from being entered into a database field.
An input mask is a textual pattern for acceptable data. Its textual because certain special characters have specific meaning. For example, the character 0 means a digit is required. Those characters are then put together in a specific order or pattern that represents the type of data that can be entered. For example, a phone number that requires an area code in parenthesis might have the following input mask:
Characters and their meaning
Below is a list of the special characters and their meaning:
|0||A digit between 0 and 9 must be entered.|
|#||A digit or a space may be entered.
The digits and spaces will appear on the screen but only the digits will be saved in the field.
|9||A digit or a space may be entered.
The digits and spaces will appear on the screen, and will be saved in the field.
|L||A letter, upper or lower case, must be entered.|
|?||A letter, upper or lower case, may be entered.|
|A||A letter or digit must be entered.|
|a||A letter or digit may be entered.|
|&||Any character, including a space, must be entered.|
|C||Any character, including a space, may be entered.|
|. ,||Decimal and thousands place holder|
|: ; - /||Time separator used to separate hours, minutes and seconds depending on Regional Settings made in the Windows Control Panel.|
|<||Forces all characters to be converted to lowercase.|
|>||Forces all characters to be converted to uppercase.|
|!||Data is displayed from right to left.|
|\||The character following the backslash will be displayed as a literal character. For example: \0 will be displayed as a 0.|
|"||Any characters between a pair of double quotes will be displayed as literal characters.|
|Password||Useful for entering passwords. Characters entered will be saved in the field but will be displayed as asterisks.|
In addition to the special characters, the input mask can have two additional sections. Each section is separated from the previous section by a semicolon.
|Section 1||Section 2||Section 3|
Section 2 – Storing literal characters
The second section of the input mask determines if literal characters are saved on the disk. Literal characters are those extra characters that format a number or text entry. For example the parenthesis surrounding an area code are literal characters. Dashes in a Social Security Number are another example of literal characters.
If you save, for example, a phone number without its literal characters, than on the disk it would be saved as just 10 digits: 4081234567 even though the input mask will display it on the screen as 14 characters: (408) 123-4567.
To have literal characters saved on the disk, enter a 0 in the second section, otherwise leave the second section blank as shown below.
|Input Mask||Displayed Phone Number||Saved Phone Number|
|\(999") "000\-0000;0||(789) 654-1230||(789) 654-1230|
|\(999") "000\-0000;||(789) 654-1230||7896541230|
Section 3 – Placeholders
When displayed on the screen, an underscore or some other character can be used as a placeholder. This will make it obvious to the users where they data can be entered. If a placeholder character is not entered in the third section, Access will by default display an underscore. If you want a different character, just enter it in the third section. If you want to use a space as the placeholder, enter a space between two quotation marks.
|Phone number field with no placeholder therefore an underscore is used||\(999") "000\-0000;0||(___) ___-____|
|Phone number field with a pound sign as a place holder||\(999") "000\-0000;0;#||(###) ###-####|
|Phone number field with a space as a place holder||\(999") "000\-0000;0;” “||( ) -|
Input Mask Cautions
Input masks can cause problems, especially if they are changed. For example, suppose you have a phone number field input mask such as \(999″) “000\-0000;0;. Notice the 0 in the second section instructs Access to store the parenthesis, dashes and phone numbers. Suppose you then change the input mask to remove the parenthesis: 999\ 000\-0000;0;. If the user then needs to edit the digits of a previous phone number. Access will display the following error unless they remove the parenthesis.
Input masks can also be a problem when the user navigates with their mouse. For example, in the screen shot below the user clicked in the middle of the Phone number field. Notice that the mouse put the cursor in the middle of the field. Before they enter the phone number the user will need to manually reposition the cursor at the beginning of the field.
In this post we have stated that an input mask is like a face mask – it can be used to filter the type of data that can go into a field. It can also provide literal characters that will bring consistency to phone numbers, zip codes, and other fields. We have learned that the literal characters can be stored in the field, or just used to format the field’s display. Finally we learned that input masks are not perfect, and can cause problems if they are ever changed, or if the user selects the field with their mouse.
Tell us what you think. Have input masks helped you, or are they more trouble than their worth?
Now that you have learned about input masks, can you determine how they will be used? Click on the mask to see the answer.
Phone # with area code and slashes as separator
Phone # with area code and slashes as separator
Phone # with optional area code inside parenthesis, and a space and dash as separators
( ) 123-4567
Phone # with area code inside parenthesis, and a space and dash as separators
Zip code with 5 required digits and 4 optional digits
Date with a two-digit day, two-digit month, and four-digit year
Date with a one or two-digit day, one or two-digit month, and four-digit year
A code that starts with a letter, followed by two digits, then a space, then an optional letter with three optional digits