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)
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.
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.