How to Use editmask of maskedit)

Source: Internet
Author: User

Recently, you need an editing box that can control the input and output formats, But Delphi does not have any control that meets the requirements! As a result, Delphi does not support regular expressions. It does not consider the feasibility of writing a regular expression parser by itself. It is not allowed to write a regular expression from the beginning to edit the box. No way. Use maskedit!
By the way, I also know the specific usage of editmask.
The following content is found online
The mask edit box (maskedit) is a special edit box. It can be used to design many complicated input formats. After selecting maskedit, You need to design an input format for it. The method is as follows:

First, select maskedit on the form, find the editmask attribute in the object Viewer (Object inspector), and double-click it to bring up a dialog box as shown in.

The input mask edit box in the upper-left corner of the dialog box is used to enter the mask format. The mask format can be divided into three parts. Each part is separated by a semicolon (;), for example, "!". 90: 90: 90:; 1 ;_". The following explains the meaning of each input format OPERATOR:

1. The first part of the input format is the mask itself, that is, the data input format. In this section, some special format characters are used to indicate the character types and formats to be entered, such as "! L0a9: C> ll <. Common maskedit input format characters include:


L and l indicate that only one letter can be filled in this position. L is the same as l, but not allowed.

A and A indicate that only one letter or number can be entered. A is the same as a, but not allowed.

C and C indicate that any character can be entered in this position. C is the same as C, but not allowed.

0 and 9 0 indicate that only one number can be entered for this position. 9 is the same as 0, but not allowed.

<And> <format characters indicate that subsequent letters are displayed in lowercase until a> Format character or <> Format character is displayed.> The format is the opposite of <.

<> This parameter indicates that case-insensitive conversion is not performed. The input format prevails.

\ Indicates the mask format operator after the format operator will be treated as a common character in the data. If you want to include a common character in the data, instead of being parsed as a mask, you can add a \ symbol before the character. For example, \.

# Indicates that you can enter a number or a positive or negative number for this position, or do not enter anything.

! ! The format character can only be placed at the first character of the mask format character, indicating that leading spaces of the input data will be removed (that is, those spaces will not be available when the editmask control value is read). No! The space after the data is removed.

And/as a standard delimiter, which can be used as part of the data. Where/is displayed as '-' rather '/'.

2. In the second part of the input format, there are only two options: 0 and 1. If the value is 1, the non-user input data, standard separators, and other characters in the mask are saved as part of the data. If the value is 0, the data is not saved.

3. The third part of the input format is used to indicate the characters used for displaying the space in the data.

With the above knowledge, Let's design an example. For example, enter a license plate number such as a CA-300019. The first two digits of the data are uppercase letters, the third digit is a system separator, And the last six digits are digits. You can design the mask format as follows:
!> Ll/000000; 1 ;_
The second part of the mask is 1, indicating that the system separator '-' will also be saved as data. The "_" in the third part indicates that when the mask editing box is empty, "_" is used to indicate the vacancy. We can also use spaces to identify vacant spaces.
Another example is a zip code such as a PO-100083, where Po represents the zip code, is a prefix in each zip code, you can design the mask format as follows:
! Po/000000; 1 ;_
On the right side of the Mask Design dialog box is sample masks, which has common preset mask formats, such as phone number and date. We can select one and make necessary adjustments. The lower left part of the dialog box is a test input column, where we can enter characters to check whether the input format is satisfactory.

First of all, I would like to ask, isn't it a mistake? It seems to be a tmaskedit object.

Editmask is mainly used to set the identifier of the mask (mask). In other words, we can use the editmask attribute provided by the maskedit object to force the user to enter valid characters.

You only need to click the button on the right of the editmask attribute to open the input mask editor dialog box. You can click "sample Masks" on the right to select a preset format, alternatively, you can directly enter the mask sub-string in the input mask. The input box in the lower left corner is used to test the input of the mask format defined on the upper left, it is also the final display format in maskedit1.

There are many types of mask format sub-operators. It is not possible to give them one by one here. I can only give you a few frequently used
# Only numbers or positive and negative numbers can be entered at the corresponding position, but not necessarily
9. Only numbers can be entered at the corresponding position, but not necessarily
0. Only numbers can be entered at the corresponding position.
C. The corresponding position can only be a sub-character, but it does not have to be input
C. Only subcharacters can be entered at the corresponding position.
! Suppose! The sub-character appears in the tmaskedit mask sub-character, then "! "The space before the sub-character is not stored as data
/Is usually used to separate data such as year, month, and day in a date
A space is automatically inserted _.
; To separate parts

For example
It can be written! 0000/00/0; 1; or 0000/00/0; 1;
The last 1 indicates that the mask sub-character will be stored in the data, for example, '/'. If it is 0, it indicates that it is not saved.
; Is used to separate parts. 0 indicates that a number must be entered,/indicates the separator '-',

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.