Establishes a mask for allowing only valid data.

Usage

Set_Property(OLECtrlEntID, "OLE.EditMask[CtrlId]", Array)

Values

Array has the following structure:

PosNameTypeDescriptionDefault
<1>MaskFormatted StringThe edit mask""
<2>LiteralFormatted StringThe mask as displayed when empty""
<3>Prompt CharTextThe character used to indicate an editable character_

Indices

IndexDescription
CtrlIdIdentifies 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:

CharDescription
0Numeric (0-9)
9Numeric (0-9) or space (' ')
#Numeric (0-9) or space (' ') or ('+') or ('-')
LAlpha (a-Z)
 ?Alpha (a-Z) or space (' ')
AAlpha numeric (0-9 and a-Z)
aAlpha numeric (0-9 and a-Z) or space (' ')
&All print character only
HHex digit (0-9 and A-F)
XHex 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

MaskLiteralDescription
(000) 000-0000(___) ___-____Phone Number
000-00-0000___-__-____Social Security Number
000.000.000.000___.___.___.___IP Address
$0,000.00$_,___.__Currency
0xHHHHHHHH0x________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)
  • No labels