APEX-AT-WORK no image

APEX character validation whichs shows all not allowed characters

Von Tobias Arnhold 5.18.2012
This time I will present a solution for a character validation on the APEX item level.
Normally you create a simple validation based on a REGULAR EXPRESSIONS which checks for a set of characters which are allowed inside your item. If there are characters inside your item which are not in the list an error will be displayed. Unfortunately the end user doesn't know the exact character which is not allowed. If you have a text-box and you allow 500 characters then this will be a problem for the usability of your application.  

Workaround
Create a new validation as:
"Function Returning Error Text"
declare
 v_text varchar2(16000) := :P1_TEXT;
 v_text_cnt number;
 v_text_err varchar2(1000);
begin
 select count(*) into v_text_cnt from dual
 where
 REGEXP_LIKE (v_text,'^[[:alpha:] .,-:;!?[:digit:]]+$');
 /* List of allowed characters */

 if v_text_cnt = 0 then
   select regexp_replace (v_text,'[[:alpha:] .,-:;!?[:digit:]]+'
      )   invalid_characters into v_text_err
   from dual;

   return 'Error. The following characters are not allowed: ' || v_text_err;
 end if;
end;

Advantage: 
The end user can search for the wrong character and fix it himself.

 I added a forum entry to it: https://forums.oracle.com/forums/thread.jspa?messageID=10237706

Post Tags: