HeaderPane
Main
Hide

SftMask/DLL 7.0 - Masked Edit Control

Share Link
Print

Input Validation

Input validation is an important part of any application as data entered by the user must be verified and validated. SftMask/DLL has a number of features designed to assist an application to validate input data.

Generally, a suitable edit mask is defined using the lpszMask field of the SFTMASK_CONTROL structure. Optionally, the lpszMsgErrorEmpty and lpszMsgErrorInvalid fields can be defined to provide error messages (lpszMsgTitle defines the message box title). SftMask/DLL will never automatically display an error message.

An application can use the IsValid function to determine if a control's input data is valid. If the equivalent IsValidWithMsg function is used instead, a suitable error message is displayed (based on the lpszMsgErrorEmpty and lpszMsgErrorInvalid fields).

The NM_SFTMASK_VALIDATIONERROR notification is sent to the parent window when various error conditions are detected. The NM_SFTMASK_CUSTOMVALIDATION notification allows an application to implement its own validation logic in addition to the mask-based validation.

Whether an empty control is considered valid is defined using the fAllowEmpty field (with a defined mask) and the fAllowEmptyWithoutMask field (without a mask).

While the control's contents are invalid, the colors defined using the colorBgInvalid and colorFgInvalid fields are used, providing immediate visual feedback. The automatic error image can also be used to indicate empty, invalid or required input.

An application must explicitly call the IsValid (or IsValidWithMsg) function to insure that the input is valid and display an error message if necessary. It is strongly discouraged to implement this in response to WM_KILLFOCUS or the SFTMASKN_KILLFOCUS notification, as this would prevent a user from clicking on a Cancel button, closing the window, etc. unless valid input is entered first. Validation of input data should typically take place in response to the user clicking on an OK, Apply or Save button.

Example

This example validates two masked edit controls when the user clicks OK. If a control's contents are invalid, a message box is displayed and the OK processing is abandoned.

case IDOK:
    if (!SftMask_IsValid_WithMsg(GetDlgItem(hwndDlg, IDC_PHONE)))
        return TRUE; // invalid, message displayed, don't close
    if (!SftMask_IsValid_WithMsg(GetDlgItem(hwndDlg, IDC_ZIP)))
        return TRUE;
    // all input valid ...
    EndDialog(hwndDlg, IDOK);
    return TRUE;

See Also Edit Masks | Error Image | IsValid | IsValidWithMsg | Notifications


Last Updated 08/30/2026 - (email)
© 2026 Softel vdm, Inc.