verification of an item text [message #580073] |
Tue, 19 March 2013 20:28 |
|
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 |
|
Littlefoot
Messages: 21823 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 |
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
|
|
|
|
|
|