verification of an item text [message #580073] |
Tue, 19 March 2013 20:28 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/379e55f070b5a4b7b6f328897bd559f9?s=64&d=mm&r=g) |
goldray
Messages: 108 Registered: December 2012
|
Senior Member |
|
|
Hi,
I want to make a verification of an item text ,the user must enter a number of length 4.
So I created a text item :number(4).
and in when-validate-item trigger of this item ,I put this code:
if length(:block.empno) != 4 then
message('this item must containonly 4 digit');
end if;
=> the problem, when the user entered "0123" ,it should be acceptable !! but this is not the case ...
any suggestions ?
|
|
|
Re: verification of an item text [message #580075 is a reply to message #580073] |
Wed, 20 March 2013 00:18 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.orafaq.com/forum/images/custom_avatars/72104.gif) |
Littlefoot
Messages: 21818 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
0123 is a string, not a number; numbers can't have a leading zero. It means that item data type can't be NUMBER - must be a CHAR.
There are different options which check whether something is (or is not) a number; I prefer regular expression one. As I don't have Forms here, I can't test whether Forms' PL/SQL supports regular expressions, so - I'd create a database function, pass item value to it; function's return value is then evaluated in a form WHEN-VALIDATE-ITEM trigger.
create or replace function f_is_item_numeric (par_item in varchar2)
return boolean
is
begin
return regexp_like(par_item, '\d+{4}');
end;
Form trigger:begin
if not f_is_item_numeric(:block_name.item_name) then
message('Invalid value');
raise form_trigger_failure;
end if;
end;
[Updated on: Wed, 20 March 2013 00:18] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: verification of an item text [message #580134 is a reply to message #580115] |
Wed, 20 March 2013 13:13 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
goldray wrote on Wed, 20 March 2013 09:43
2)it does not accept numbers that begin with 0 example 0123 => in DB :123
Your response is not accurate. It "accepts" 0123 just fine, but as you have been told, numbers do not start with zero. Why do you not understand this simple concept? Do you really not understand why putting 0123 in a number column would store it as 123?
[Updated on: Wed, 20 March 2013 13:14] Report message to a moderator
|
|
|
|
|
|