Wednesday, March 16, 2016

Watch out: validating number type items

I've discovered a strange behavior in APEX that I thought it works out of the box. It's about validation of the number type items.

Simple Case

1) I've created two number items on a page, named P16_MIN_VALUE and P16_MAX_VALUE, and a submit button:

2) Next, I've added the validation that checks if P16_MAX_VALUE is greater or equal than P16_MIN_VALUE


If you put 2 in field Min value and 1 in filed Max value, the validation message is displayed on screen (as expected):

If you put 12 in field Min value and 2 in filed Max value, the validation message is NOT displayed on screen. You'll see success message:

The problem (or unexpected behavior) is that APEX doesn't validates number type items as numbers but as strings.

Demo is available here.


I can't say if this is a bug or expected behaviour because there's no documentation about it (or at least I didn't found it). I know there are functions for getting numeric value of an item: apex_util.get_numeric_session_state and NV but I thought if you have a numeric item and you use it as a bind variable that it will be "binded" like a number.

So, the solution is to explicitly convert your items to numbers or to use one of those functions mentioned above. Your validation should look like this:

...or even better, write your logic in packages with number input parameters.

Enjoy! ;)

Tested on APEX