Verifying Numeric Input

David Bovill david at openpartnership.net
Mon Aug 18 03:57:55 EDT 2008


How about something like this Rob?

function valid_Number theString, allowCurrency
>     if allowCurrency is not false then
>         put "[" & "€£\$" & "]?" into currencyList
>     else
>         put empty into currencyList
>     end if
>     put "^" & currencyList &
> "([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$"
> into someReg
>     get matchText(theString, someReg, foundTextVarsList)
>     put foundTextVarsList
>     return it
> end valid_Number


Would be interested to see how it compares - with speed and different
inputs.

NB like to use regular expressions for things like this because I can
leverage the work lots of people outside of the Rev community - regular
expressions are available in most languages. It can also help with
portability. Mostly speed of coding. Of course it does't allways work out
that way - you can spend ages getting into a real mess with a regular
expression - but it would be interesting to compare this case - it took me
about 5 minutes to code this function (longer to write this email). I
searched the regular expression library I have bookmarked -
http://regexlib.com/Search.aspx?k=currency&c=-1&m=-1&ps=20 - found the one I
liked and wrapped it in a function. Compare that to how long did it took to
code the Rev function. What's more if I came back in 6 months time, or found
a bug, often it would have been spotted in the Regexp library already and
I'd just have to copy and paste the new one.



More information about the use-livecode mailing list