As for finding valid and invalid (turns out I need both, but need to know the difference) this might work:
Code:
local valid = true
for w in string.gmatch(text_store, "%d+") do
if string.gmatch(w, "i:%d+") then
valid = true
else
valid = false
break -- we only need to find one incorrect itemID. no point in continuing
end
end