To view a printable version of this article in a PDF viewer, click here for PDF.
This white paper describes data validation in Input Pro controls. After a general overview of data validation, the paper provides detailed information about data validation in each of the Input Pro controls that performs data validation.
Data validation is the process by which the control determines if supplied data is valid. All the formatted edit controls and the fpMemo control provide data validation.
You can customize how the control defines invalid data and when the control validates the data. In addition, you can turn off data validation.
Each control provides default settings that define valid data for the control. Each control also provides additional properties to let you change the default settings or define additional types of invalid data. For example, the fpCurrency control has predefined minimum and maximum values, which you can change if you prefer.
For a list of the default settings and available properties for defining valid data for each control, see the following sections:
Back to the top.
When Is Data Validated?
All the formatted edit controls can validate data when the data is being entered in the control and when the control loses the focus.
The formatted edit controls consist of the fpCurrency, fpDateTime, fpDoubleSingle, fpLongInteger, fpMask, and fpText controls. These controls are formatted edit controls because they can validate data according to a provided set of valid data, and they can format the data in the control. The validation and formatting for these controls for data entered by users are controlled by the UserEntry property, which for all controls except the fpDateTime control, is set by default to 0 (Formatted).
The following sections describe in detail what happens
As Data Comes into the Control
Data comes into the control from four sources: the user typing, the user pasting, a database, or code. All the controls differentiate between the sources of the data when the data comes into the control as follows:
- For all the formatted edit controls except the fpMask control, the control validates the data as the user enters the data, either by typing or pasting it into the control. The control does not validate data from code or a database as it comes into the control; it validates such data only when the control loses the focus.
- The fpMask control and the fpMemo control validate all data as it is entered into the control, no matter the source of the data.
Besides the preceding methods, the fpDateTime control also allows users to input a date from a pop-up or drop-down calendar or clock, and the formatted edit controls can let users change data in the control using buttons.
What Does the Control Do as Data Comes into the Control?
All the controls that provide data validation can check data as the user types it or pastes it into the control. The control checks the data against its criteria for valid data.
The following table provides a summary of how the controls behave:
| Control || Behavior |
| fpCurrency, fpDoubleSingle, fpLongInteger, fpText || These controls by default check data as the user types it or pastes it into the control. They cannot check data as it is provided from a database or code. |
| fpDateTime || The fpDateTime control can check data as the user types it or pastes it into the control, but this control does not do so by default. It cannot check data as it is provided from a database or code. |
| fpMask and fpMemo || The fpMask and fpMemo controls by default validate not only data typed or pasted by the user as it is entered, but also data provided from code or a database as it comes into the control. |
If you prefer that a formatted edit control not validate the data as it is typed or pasted by the user and instead accept any data provided, set the UserEntry property for the control to 1 (Free Format). For the fpMask control, you can prevent the control from validating data provided from code or a database by setting the BestFit property to True. You cannot turn off data validation for the fpMemo control.
How Does the Control Respond to Invalid Data?
While the user is entering data, if the control is validating the data being entered, the control responds to invalid data by blocking the data and firing the UserError event. You can respond to the UserError event to provide information to the user about what valid data is for this control.
The control can also sound a beep when the user enters invalid data. You can turn on the ability to sound a beep by setting the AutoBeep property to True or by setting the AutoBeep parameter in the UserError event to True.
If a formatted edit control provides buttons for users to change the value in the control, the buttons can stop changing the value to prevent invalid data (for example, the control can stop incrementing or decrementing the value in response to the buttons). To use the buttons to prevent invalid data, set the ButtonIndex, ButtonMin, ButtonMax, and ButtonWrap properties.
When the control is validating the data as the user enters it, there are certain situations when invalid data can be typed or pasted into the control, as described in the sections for the fpCurrency, fpDateTime, fpDoubleSingle, and fpLongInteger controls.
When the Control Loses the Focus
By default, all the formatted edit controls and the fpMemo control validate the data in the control when the control loses the focus, no matter the source of the data. The control checks the data against its criteria for valid data.
When a control receives data from code or from a database and does not currently have the focus, the control does not receive and then lose the focus when the data is placed into the control. Instead, if the control does not have the focus when it receives the data, the control validates the data when the data is placed into the control, similar to when the control validates the data as it loses the focus after the user types it. Throughout this paper, references to the control's behavior when it "loses the focus" are also intended to describe the control's behavior when it receives data from code or a database and does not have the focus.
What Does the Control Do when It Loses the Focus?
When the control loses the focus, the control tries to format the data in the contr