Establishes a mask for allowing only valid data.
Usage
Set_Property(OLECtrlEntID, "OLE.EditMask[CtrlId]", Array)
Values
Array has the following structure:
Pos | Name | Type | Description | Default |
---|---|---|---|---|
<1> | Mask | Formatted String | The edit mask | "" |
<2> | Literal | Formatted String | The mask as displayed when empty | "" |
<3> | Prompt Char | Text | The character used to indicate an editable character | _ |
Indices
Index | Description |
---|---|
CtrlId | Identifies a subclassed control |
Remarks
Applies To: EDITLINE, EDITBOX
The EditMask property can be used to guide the users input. An edit mask limits characters the user may enter and automatically formats the data so it's always valid. For example you could establish a mask for a phone number, which would initially look like this:
As the user types, only numbers are allowed, and they automatically replace the underscore characters:
When the user reaches the end, no more characters can be added:
The EditMask property has three fields:
Mask
This establishes which characters the user is allowed to type. Most characters in this mask are treated as literals. The following characters have a special meaning:
Char | Description |
---|---|
0 | Numeric (0-9) |
9 | Numeric (0-9) or space (' ') |
# | Numeric (0-9) or space (' ') or ('+') or ('-') |
L | Alpha (a-Z) |
? | Alpha (a-Z) or space (' ') |
A | Alpha numeric (0-9 and a-Z) |
a | Alpha numeric (0-9 and a-Z) or space (' ') |
& | All print character only |
H | Hex digit (0-9 and A-F) |
X | Hex digit (0-9 and A-F) and space (' ') |
> | Forces characters to upper case (A-Z) |
< | Forces characters to lower case (a-z) |
Literal
This field defines the editable characters, i.e., the editable positions within the mask. Editable characters are established by the presence of the underscore character. The literal string should be the same length as the mask. In parallel, the work together to acheive the final masking result.
Correct:
Mask = "Home Phone: (000) 000-0000" Literal = "Home Phone: (___) ___-____"
Incorrect:
Mask = "(000) 000-0000" Literal = "Home Phone: (___) ___-____"
See below for examples.
Prompt Char (Optional)
This field simply allows you to optionally change the prompt character. Setting this field will replace the underscores in your Literal with the given character.
Samples
Here is a table of sample masks
Mask | Literal | Description |
---|---|---|
(000) 000-0000 | (___) ___-____ | Phone Number |
000-00-0000 | ___-__-____ | Social Security Number |
000.000.000.000 | ___.___.___.___ | IP Address |
$0,000.00 | $_,___.__ | Currency |
0xHHHHHHHH | 0x________ | Hex |
00/00/00 | __/__/__ | Date |
00:00 | __:__ | Time |
>>>>>> | ______ | Six Uppercase Characters |
<<<<<< | ______ | Six Lowercase Characters |
LLLLLLLL | ________ | Eight Alphabetic Letters (No Digits or Punctuation) |
AAAAAAAA | ________ | Eight Letters or Numbers |
Cut and Copy operations only copy the editable characters to the clipboard. Paste and Undo operations preserve the mask as well.
Example
// Set a phone number mask Mask = "" Mask<1> = "(000) 000-0000" Mask<2> = "(___) ___-____" // Subclass the control (skip this if you've done it once already) CtrlId = @Window:".EDITLINE" Handle = Get_Property(CtrlId, "HANDLE") rv = Send_Message(@Window:".OLE_SUBCLASS", "OLE.Subclass", Handle, CtrlId) // Set the mask (remember to use ; instead of .) Convert "." to ";" in CtrlId Set_Property(@Window:".OLE_SUBCLASS", "OLE.EditMask[":CtrlId:"]", Mask)