Home » Developer & Programmer » Forms » verification of an item text (oracle forms 10g ,win xp pack 2)
verification of an item text [message #580073] Tue, 19 March 2013 20:28 Go to next message
goldray
Messages: 104
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 messageGo to next message
Littlefoot
Messages: 18826
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 #580110 is a reply to message #580075] Wed, 20 March 2013 08:09 Go to previous messageGo to next message
goldray
Messages: 104
Registered: December 2012
Senior Member
thank you ,but I don't understand this one:\d+{4}
its possible to use this regexp: ^0[0-9]+$ ?
Re: verification of an item text [message #580111 is a reply to message #580110] Wed, 20 March 2013 08:16 Go to previous messageGo to next message
Littlefoot
Messages: 18826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
The fact you don't understand it doesn't mean that it is wrong (you'd rather LEARN what it means). It says: check exactly 4 consecutive digits. Of course, you can use any code you find appropriate. If you think that your code does the job, go ahead. (I think it doesn't).
Re: verification of an item text [message #580115 is a reply to message #580111] Wed, 20 March 2013 08:43 Go to previous messageGo to next message
goldray
Messages: 104
Registered: December 2012
Senior Member
I tested your suggestion:
1)It accept the number whose length <4 !!
2)it does not accept numbers that begin with 0 example 0123 => in DB :123
Re: verification of an item text [message #580116 is a reply to message #580115] Wed, 20 March 2013 08:53 Go to previous messageGo to next message
Littlefoot
Messages: 18826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Here's my test. Please, post yours.

SQL> create or replace function f_is_item_numeric (par_item in varchar2)
  2    return boolean
  3  is
  4  begin
  5    return regexp_like(par_item, '\d+{4}');
  6  end;
  7  /

Function created.

SQL> begin
  2    if not f_is_item_numeric('&input_value') then
  3       dbms_output.put_line('Invalid');
  4    else
  5       dbms_output.put_line('Valid');
  6    end if;
  7  end;
  8  /
Enter value for input_value: 0123
Valid

PL/SQL procedure successfully completed.

SQL> /
Enter value for input_value: abc
Invalid

PL/SQL procedure successfully completed.

SQL> /
Enter value for input_value: 12
Invalid

PL/SQL procedure successfully completed.

SQL>
Re: verification of an item text [message #580117 is a reply to message #580116] Wed, 20 March 2013 09:00 Go to previous messageGo to next message
Littlefoot
Messages: 18826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Huh, I was wrong (allowing more than 4 digits).

Here's a fixed regular expression code.
SQL> /
Enter value for input_value: 12345
Valid

PL/SQL procedure successfully completed.

SQL> -- Aha! Wrong! I'll have to fix it!
SQL> CREATE OR REPLACE function f_is_item_numeric (par_item in varchar2)
  2    return boolean
  3  is
  4  begin
  5    return regexp_like(par_item, '^\d{4}$');
  6  end;
  7  /

Function created.

SQL> begin
  2    if not f_is_item_numeric('&input_value') then
  3       dbms_output.put_line('Invalid');
  4    else
  5       dbms_output.put_line('Valid');
  6    end if;
  7  end;
  8  /
Enter value for input_value: 12345
Invalid

PL/SQL procedure successfully completed.

SQL> /
Enter value for input_value: 1234
Valid

PL/SQL procedure successfully completed.

SQL> /
Enter value for input_value: 0123
Valid

PL/SQL procedure successfully completed.

SQL> /
Enter value for input_value: 12
Invalid

PL/SQL procedure successfully completed.

SQL>
Re: verification of an item text [message #580119 is a reply to message #580117] Wed, 20 March 2013 09:32 Go to previous messageGo to next message
goldray
Messages: 104
Registered: December 2012
Senior Member
thank you
its works

[Updated on: Wed, 20 March 2013 10:57]

Report message to a moderator

Re: verification of an item text [message #580129 is a reply to message #580119] Wed, 20 March 2013 11:41 Go to previous messageGo to next message
goldray
Messages: 104
Registered: December 2012
Senior Member
Sir, what is the type of :block.item ??
Re: verification of an item text [message #580134 is a reply to message #580115] Wed, 20 March 2013 13:13 Go to previous messageGo to next message
joy_division
Messages: 4454
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

Re: verification of an item text [message #580141 is a reply to message #580134] Wed, 20 March 2013 13:50 Go to previous messageGo to next message
goldray
Messages: 104
Registered: December 2012
Senior Member
I want to have "0123" in the DB ,I understand the concept ...
=>I just need it, after level calculations
it's possible or not ?
Re: verification of an item text [message #580147 is a reply to message #580141] Wed, 20 March 2013 14:49 Go to previous messageGo to next message
Littlefoot
Messages: 18826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Possible, within the VARCHAR2 or CHAR data type.
Re: verification of an item text [message #580151 is a reply to message #580147] Wed, 20 March 2013 17:23 Go to previous message
goldray
Messages: 104
Registered: December 2012
Senior Member
thank you
Previous Topic: Killing inactive form session through oracle application server
Next Topic: ORA-12154: TNS:could not resolve the connect identifier specified - Forms 10G
Goto Forum:
  


Current Time: Fri Apr 18 05:58:20 CDT 2014

Total time taken to generate the page: 0.12858 seconds