View previous topic :: View next topic
|
Author |
Message |
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
Hi,
I am getting the input from user to run a rexx program.
I need to validate that input if numeric or non-numeric.
Could you please help me on this.
Also please provide me the link if this topic is already available in the forum.
Thank you. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the topic is available in the REXX manuals
see the datatype function
or google for rexx datatype |
|
Back to top |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
OK thanks |
|
Back to top |
|
|
MBabu
Active User
Joined: 03 Aug 2008 Posts: 400 Location: Mumbai
|
|
|
|
Be aware that datatype marks more than just numerics as numbers. Scientifc notation is also considered a number
Code: |
say datatype('1E12')
NUM |
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
Perhaps use translate:
Code: |
/* rexx */
mynum = '1E12'
If translate(mynum,' ','1234567890') ¬= ' ' Then
/* add error message */ |
If there are any non-numeric characters, the result is non-blank. |
|
Back to top |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
Thanks for letting me know about these things as I am new to RExx.
Actually, I referred the manual and used,
Code: |
if datatype(L1,W) /== '1' then do
/* error message */
|
Where L1 is a variable having input data.
'W' refers to whole number.
Hence if L1 is whole number, rexx returns 1 otherwise 0 which is an error.
Please correct me if my understaning is incorrect. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Your understanding of this function sounds right. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
As REXX always returns a number, you can do a numeric comparison:
Code: |
if datatype(L1,W) <> 1 then do
/* error message */ |
In my programs, when dealing with functions that return 0 or 1, I use the following trick:
In my Init paragraph (at the beginning of execution):
Code: |
True = (1=1)
False = /True |
Then I can ask:
Code: |
if datatype(L1,W) = False then do
/* error message */ |
|
|
Back to top |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
oh great.
everything i hear from this forum is new!
Thanks for your information/guidance. |
|
Back to top |
|
|
arun.masilamani
New User
Joined: 26 Jun 2008 Posts: 4 Location: Chennai
|
|
|
|
You could also us this form of "DATATYPE" Validation too :
Code: |
PULL INPUT
IF DATATYPE(INPUT) = "NUM" THEN
SAY "NUMBER IS NUMERIC"
ELSE
SAY "NUMBER IS NOT NUMERIC"
|
|
|
Back to top |
|
|
|