Skip to Main Content

New

Reusable Validation Framework in Oracle APEX

Published on 31 Dec 2025 by CHATURVEDINIDHI26@GMAIL.COM


     

Reusable Validation Framework in Oracle APEX

In enterprise Oracle APEX applications, validation is not just about checking values. A professional validation framework should:

     
  • Show error messages exactly below the related item
  •  
  • Display errors in the notification area
  •  
  • Allow users to click on the error message and jump to the field
  •  
  • Be reusable across multiple pages

This article explains how to build and use a centralized validation package in Oracle APEX that fulfils all these requirements.

1. Why Centralized Validation Instead of Page-Level Validation

In many APEX applications, validations are created individually on each page. This approach becomes difficult to maintain as the application grows.

A centralized PL/SQL package:

     
  • Eliminates duplicate validation logic
  •  
  • Ensures consistent error messages
  •  
  • Makes maintenance easier
  •  
  • Improves overall user experience

2. Mandatory Field Validation (Generic Functionality)

The first functionality of our framework is a generic mandatory field validation. This procedure can validate any page item by simply passing the value and item name.

PL/SQL Procedure Logic

  
PROCEDURE validate\_mandatory (  
 p\_value     IN VARCHAR2,  
 p\_item\_name IN VARCHAR2,  
 p\_label     IN VARCHAR2  
) IS  
BEGIN  
 IF p\_value IS NULL THEN  
   apex\_error.add\_error(  
     p\_message          => '<a href="#'||p\_item\_name||'">'||p\_label||' is required</a>',  
     p\_display\_location => apex\_error.c\_inline\_with\_field\_and\_notif,  
     p\_page\_item\_name   => p\_item\_name  
   );  
 END IF;  
END;  
Key Point:   The p\_page\_item\_name parameter ensures that when the user clicks on the error message, the cursor automatically focuses on the corresponding item.

3. Identity Validation (Email, Phone, PAN, GSTIN)

Apart from mandatory checks, enterprise applications often require format-level validations such as:

     
  • Email format
  •  
  • Mobile number pattern
  •  
  • PAN structure
  •  
  • GSTIN structure

This functionality is handled by a single procedure that validates all identity fields in one call.

Email Validation Example

  
IF p\_email\_required AND p\_email IS NULL THEN  
 apex\_error.add\_error(  
   p\_message          => '<a href="#P\_EMAIL">Email is required</a>',  
   p\_display\_location => apex\_error.c\_inline\_with\_field\_and\_notif,  
   p\_page\_item\_name   => 'P\_EMAIL'  
 );  
ELSIF p\_email IS NOT NULL  
 AND NOT REGEXP\_LIKE(  
   p\_email,  
   '^\[A-Za-z0-9.\_%+-\]+@\[A-Za-z0-9.-\]+\\.\[A-Za-z\]{2,}$'  
 ) THEN  
 apex\_error.add\_error(  
   p\_message          => '<a href="#P\_EMAIL">Invalid Email format</a>',  
   p\_display\_location => apex\_error.c\_inline\_with\_field\_and\_notif,  
   p\_page\_item\_name   => 'P\_EMAIL'  
 );  
END IF;  

4. How to Use the Validation Package on an APEX Page

All validations are executed from a single After Submit page process. This keeps the page clean and readable.

Page Process Code Example

  
BEGIN  
 validation\_master\_pkg.validate\_mandatory(  
   p\_value     => :P9999\_COMPANY\_CODE,  
   p\_item\_name => 'P9999\_COMPANY\_CODE',  
   p\_label     => 'Company Code'  
 );

 validation\_master\_pkg.validate\_mandatory(  
   p\_value     => :P9999\_USERNAME,  
   p\_item\_name => 'P9999\_USERNAME',  
   p\_label     => 'Username'  
 );

 validation\_master\_pkg.validate\_mandatory(  
   p\_value     => :P9999\_PASSWORD,  
   p\_item\_name => 'P9999\_PASSWORD',  
   p\_label     => 'Password'  
 );  
END;  

5. User Experience Outcome

     
  • Error messages appear directly below the item
  •  
  • Errors are also listed in the notification area
  •  
  • Clicking on an error moves the cursor to the field
  •  
  • Once the user enters a value and submits, the error is removed automatically

6. Conclusion

By using a centralized validation package in Oracle APEX, we achieve:

     
  • Clean page design
  •  
  • Reusable validation logic
  •  
  • Consistent and professional error handling
  •  
  • Improved end-user experience

This framework is production-ready and suitable for large enterprise APEX applications.

📝 Nidhi Blog

Sharing knowledge, tutorials, and stories about Oracle APEX, development, and digital growth.

📧 Contact

Email: support@nidhispace.com

Follow us on:
linkedin | YouTube


© Nidhi Blog. All rights reserved.