Page 1 of 1
Check for numbers only
Posted: Tue Feb 12, 2013 12:14 am
by Nakia
Hi,
I have a txt fld that I wish to validate as only containing numbers.
I am using the below and it works with the exception of when the fld contains more han 1 of the same number (example 22,11,55)
Suggestions on how to go about resolving..
Code: Select all
if tTheFldText is in "0123456789" then
Re: Check for numbers only
Posted: Tue Feb 12, 2013 12:43 am
by Simon
Try:
isNumber is in the dictionary.
Simon
Re: Check for numbers only
Posted: Tue Feb 12, 2013 12:51 am
by dunbarx
Hi.
Not sure about all that you said. For example, will your field contain items only (like you posted, "22,11,55")? Or some other format? Will it contain alphanumeric data like "A123"? And if so, do you want to strip the "A", or just tag the whole string?
Anyway, what you ask will be simple and fun to work out. As one of many possible approaches, you should look up the operator "is a/is not a". This might be used as follows, assuming the items in your example:
repeat for each item testItem in tFieldText
if testItem is not a number then put testItem & return after collectedBadData
end repeat
You will parse your data, either by character, item, word, or line, and test each of those chunks to see if they are a number. The engine has that power built in. You can collect the bad data or the good, or just delete the bad, or send an alert, or whatever you wish.
As a sidenote, your example would only work with individual characters tested one by one as per the above, and maybe that is a part of your script that you do not show. I suppose it would also work with the string "0123456789", but I bet that is not what you meant.
Anyway, play with this, and then try to do it a completely different way. Write back with what you discover.
Craig Newman
Re: Check for numbers only
Posted: Tue Feb 12, 2013 1:00 am
by dunbarx
Simon uses a more compact function "isNumber" instead of the operator "is a". That is perfectly valid.
But your example had "22,11,55" This is a string of three items, in LC parlance, all of which are numbers, it is true, but both Simon's and my offerings will fail if you try to test that whole string as a number. It is not. It is a string of three numbers separated by commas.
These must be dealt with separately.
Or is your data always one string of characters? If so, the problem becomes much simpler, and either the function or the operator can work in one go. Let us know how your data is formatted.
This does not mean you should not still play with the other stuff. You must.
Craig Newman
Re: Check for numbers only
Posted: Tue Feb 12, 2013 1:29 am
by mwieder
Or
Code: Select all
replace comma with empty in tTheFldText
Re: Check for numbers only
Posted: Tue Feb 12, 2013 1:52 am
by Nakia
isNuber worked the treat.
My example (22,11 etc) was just giving examples of different combo's of more than one number