Validation of Item [message #625961] |
Fri, 17 October 2014 02:32  |
Xandot
Messages: 235 Registered: January 2014 Location: India
|
Senior Member |
|
|
Hello ,
I have two field "Type" (list item varchar2,Number) and "Value" (datatype is varchar2) by default its varchar2 so user insert varchar2 data but if user select number in Type list then user should only insert numeric data.
how can i create validation for restrict the user to enter numeric data.
Thanks,
Xandot
|
|
|
|
Re: Validation of Item [message #626045 is a reply to message #626014] |
Mon, 20 October 2014 03:17   |
Xandot
Messages: 235 Registered: January 2014 Location: India
|
Senior Member |
|
|
I have one condition also like if the "Type=Number" then only check the validation so how can i apply condition in validation ..i have already try this
------Validation Expression 1-------
if Type ='N' then
regexp_like(:PAGE_ITEM, '^\d+$');
end if;
But Its not working ..Please help me
Thanks
|
|
|
|
Re: Validation of Item [message #626122 is a reply to message #626051] |
Tue, 21 October 2014 01:41   |
Xandot
Messages: 235 Registered: January 2014 Location: India
|
Senior Member |
|
|
When i implement the validation with Boolean return then some error is coming like :--
--Error ERR-1021 Unable to run "function body returning boolean" validation.
if Type='N' then
return regexp_like(:Page_item, '^\d+$');
end if;
Thanks,
Xandot
|
|
|
Re: Validation of Item [message #626128 is a reply to message #626122] |
Tue, 21 October 2014 02:13   |
 |
Littlefoot
Messages: 21797 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
This is not a function body that returns Boolean; a function body begins with a BEGIN and ends with an END. Besides, you can't reference "type" item that way - it requires a colon sign.
I created a simple page with two items: one is P7_TYPE (select list with two values: "NUMBER" and "VARCHAR2") and another one is P7_VALUE (text item).
Then I created validation on P7_VALUE item. Its type is PL/SQL, a function that returns Boolean:return case when :P7_TYPE = 'NUMBER' then
regexp_like(:P7_VALUE, '^\d+$')
end; Error message saying "Wrong value", "Always execute" property set to "Yes".
Sample execution:

Note that the above simple regular expression catches only integers; for decimal numbers, modify it to regexp_like(col, '^-?[[:digit:],.]*$')
There are other methods (more accurate, that would catch exponents and stuff) that distinguish numbers from strings - search the Internet, you'll find many examples. However, if you are satisfied with the above suggested regular expression, that should be OK.
|
|
|
|