Compare numeric strings with leading zeros

Thierry Douez th.douez at gmail.com
Thu Sep 3 23:56:57 EDT 2015


Hi,

> Ahhhhhhhhh,

Well, nothing very dangerous here :)

>>   if matchText( userTyping, myVeryStrongPassword) then ...

This was a direct answer to this thread:

         "compare numeric strings with leading zeros" !


> I would caution against using matchText for this purpose,
> because the second
> parameter is treated by the function as a regular expression.


Yes,
myVeryStrongPassword is a regular expression in a pure litteral form.


>
> For instance, matchText would return true if you were to reverse your
> example values:

Yes, the order of the parameters have a meaning, but this is true
for so much functions in LC. So, I don't get it :(


> In addition,
> since passwords are typically allowed to contain any character

Was not asked by the OP.

Ok then, so new  rules here:)

>    local userTyping = "5"
>    local myVeryStrongPassword = "^5$"

If your password can contains any chars,
Just tell it to matchText():

    my password can be any character and I don't want you to
    interpret them in any ways!

For that,
enclose your myVeryStrongPassword by "\Q" & "\E" and it
will be interpreted as litteral characters.


> Since Ralph is looking to use this for password validation,
> I would throw in a case sensitivity check as well:

For this one, there is nothing special to do.
If it will be case insensitive you could add a prefix to the regex: (?i)

so the final matchText() solution is:

put  "\Q^5$\E"  into  myVeryStrongPassword
if matchText( userTyping,  myVeryStrongPassword ) then ...


Ok, now I'm waiting for what I've missed...

Have all a nice day or night.

Thierry




More information about the use-livecode mailing list