Livecode's isNumber returns true when certain text strings are used. isNumber("one") returns true. I need a "strict" isNumber function where any strings would return false. Needs to handle +/-, integers, reals, e notation preferably. I'm looking for a PCRE regex for matchText(pValue, regexHere)
Asked
Active
Viewed 205 times
3
-
This is not a duplicate. I've tried the solutions that are pointed to in the duplicate questions pointed out and these DO NOT WORK in Livecode Script. Please before marking as a duplicate, open up Livecode and try the 5 solutions provided (none of which are livecode examples). – Bob Hall Oct 07 '15 at 12:27
-
FWIW I've voted to reopen - it does sound like [LiveCode supports the standard PCRE library](http://lists.runrev.com/pipermail/use-livecode/2013-January/181460.html), so the examples in those answers _should_ work. Could you edit your question to include further examples of which of those you have tried - perhaps it's an issue of string escaping etc? – James Thorpe Oct 07 '15 at 12:50
-
My thinking must be off on how matchText works. Here's a list of pValues and results put matchText(pValue, "[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") 1 true 1.2 true -12.87 true 2e2 true hello false 4hello true??? this is 2 times true??? It appears as along as the matching text appears somewhere in the string, we get true back. Darn. not what I was looking for. – Bob Hall Oct 07 '15 at 13:41
-
try adding `^` at the start and `$` at the end - those are the "start of string" and "end of string" anchors in regex - ie it should ensure you match the _whole_ string, not just a portion of it – James Thorpe Oct 07 '15 at 13:44
-
1I have voted to re-open this question. As soon as it is re-opened, I'll post my answer, which is really, really simple. No regex involved. – Mark Oct 07 '15 at 14:54