Previous
Previous
 
Next
Next

Understanding Validations

You can define a validation declaratively by selecting a validation method. You enter the actual validation edit check in the Validation Messages field. Be aware that if a validation fails, subsequent page processes or computations will not occur. Also remember that the validation you enter must be consistent with the validation type you selected. For more information about validation types, see online Help.

Topics:

Creating a Validation

To create a validation:


Note:

Text entered for validations may not exceed 3,950 characters.

  1. Navigate to the appropriate Page Definition. See "Accessing a Page Definition".

  2. Under Validations in Page Processing, click the Create icon.

    The Create Validation Wizard appears.

  3. Select a validation level:

    • Item level validations are specific to a single item.

    • Page level validations do not apply to any single item, but apply to an entire page.

  4. If you selected Item level validation, select the item to be validated and click Next.

  5. Select a validation method as described in Table: Validation Methods.

    Validation Methods

    Validation Method Descriptions

    SQL

    Compares item values to data in the database.

    For example, you can use a SQL validation to verify whether a last name typed into a field exists in the database. In the following Exists SQL validation, the field is named P1_LAST_NAME and the table is named customers.

    SELECT 1 FROM customers 
    WHERE last_name = :P1_LAST_NAME
    

    PL/SQL

    Useful if you need complex logic to validate entered data.

    For example, suppose you need to create a validation for an address form that requires the user to enter a province if the address is not in the United States. You could create the validation as a Function Returning Boolean, using the following PL/SQL:

    BEGIN
      IF :P1_COUNTRY = 'US' AND :P1_PROVINCE IS NULL THEN
         RETURN FALSE;
      ELSE
        RETURN TRUE;
      END IF;
    END;
    

    You could also create the same validation implemented as a PL/SQL Expression as follows:

    NOT (:P1_COUNTRY='US' AND  :P1_PROVINCE IS NULL);
    

    Item Level Null

    Checks if an item's value in session state is null.

    For example, you could validate that the user enters a value in a field by creating an item validation and then selecting the validation method Item Not Null.

    Item String Comparison

    Compares the value of an item to a specific string.

    There are several string comparison validations that compare the value of an item to a literal string. For example, you select the validation type Item in Expression 1 is contained in Expression 2 to validate a user entry in a field against a list of values you provide.

    In Expression 1, enter the name of the item you want to validate without a colon. For example:

    P1_VALUE
    

    In Expression 2, enter a string of values you want to validate against. For example:

    ABC/DEF/GHI
    

    Regular Expression

    Regular expressions provide a method to describe text patterns. Use a Regular Expression validation to perform data validation.

    For example, you could use the following regular expression validation to verify that a string of entered data always consists of groups of six numbers separated by commas and followed by a comma:

    ^([[:digit:]]{6},)+$
    

    This regular expression would find the following entries valid:

    123456,654321,

    123456,

    123456,123456,654321,

    However, the following would not be valid:

    123456,12345

    12345


  6. For SQL, PL/SQL, and Item String Comparison validations, select the type of validation you want to create and click Next.

  7. Specify the sequence and validation name and click Next.

  8. Depending upon the validation method, enter the validation or message text that displays if the validation fails. Click Next.

  9. Define conditions that apply to this validation and click Create.

Defining How Validation Error Messages Display

You can choose to have validation error messages display inline (that is, on the page where the validation is performed) or on a separate error page.

To define how a validation error message displays:

  1. Navigate to the appropriate Page Definition. See "Accessing a Page Definition".

  2. Under Validations, select the appropriate validation.

    The attributes page for the validation appears.

  3. Scroll down to Error Message.

  4. In Error Message, enter your error message text.

  5. From Error message display location, select a display location.

    This attribute identifies where a validation error message displays. Validation error messages can display on an error page or inline within the existing page. Inline error messages can display in a notification area (defined as part of the page template) or within the field label.

    To create a hard error that stops all processing (including validations), you must display the error on an error page.

  6. If you select Inline with Field or Inline with Field and in Notification, you must associate an item with the error message. To associate an item with the error message, select the item from the Associated Item list.

  7. Click Apply Changes.


Tip:

If you select Inline with Field or Inline with Field and in Notification, be aware that the Application Express engine does not execute computations or processes during the re-rendering of the page when the validation error messages appear.

Processing Validations Conditionally

You can control when and if a validation is performed under Conditions.

To create a condition for an existing validation:

  1. Navigate to the appropriate Page Definition. See "Accessing a Page Definition".

  2. Under Validations, select the appropriate validation.

    The attributes page for the validation appears.

  3. Scroll down to Conditions.

  4. To have a validation performed when a user clicks a particular button, make a selection from the When Button Pressed list.

  5. Make a selection from the Condition Type list.

  6. Depending upon the selected Condition Type, enter values in the Expression attributes. The validation will be rendered or processed if the specified condition is met.

  7. Click Apply Changes.