Hide

SftMask/OCX 7.0 - ActiveX Masked Edit Control

Display
Print

Input Validation

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

Generally, a suitable input mask is defined using the Mask property. Optionally, the MessageEmpty and MessageInvalid properties can be defined to provide error messages. SftMask/OCX will never automatically display an error message.

An application can use the Contents.Valid property to determine if a control's input data is valid. If the equivalent ValidMsg property is used instead, a suitable error message is displayed (based on the MessageEmpty and MessageInvalid properties).

The ValidationError event occurs when various error conditions are detected.

An application must explicitly call the Contents.Valid (or ValidMsg) property to insure that the input is valid and display an error message if necessary. It is strongly discouraged to implement this in an event such as LostFocus, WM_KILLFOCUS, FocusOut, etc. as this would prevent a user from clicking on a Cancel button, close 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 (VB)

This example assumes an ADO Data Control (Adodc1), two masked edit controls, a Next and a Previous button for record navigation on the form. Some properties, such as Mask, MessageEmpty and MessageInvalid are set at design-time using the property pages).

Function CheckInputFields() As Boolean
    ' validate all input fields
    CheckInputFields = False
    If Not SftMask1.Contents.ValidMsg Then Exit Function
    If Not SftMask2.Contents.ValidMsg Then Exit Function
    CheckInputFields = True
End Function

Private Sub PrevButton_Click()
    If Not CheckInputFields() Then Exit Sub
        If Not Adodc1.Recordset.BOF Then
            Adodc1.Recordset.MovePrevious
        If Adodc1.Recordset.BOF Then
            Adodc1.Recordset.MoveFirst
        End If
    End If
End Sub

Private Sub NextButton_Click()
    If Not CheckInputFields() Then Exit Sub
        If Not Adodc1.Recordset.EOF Then
            Adodc1.Recordset.MoveNext
        If Adodc1.Recordset.EOF Then
            Adodc1.Recordset.MoveLast
        End If
    End If
End Sub

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.