I'm sure I'm being dumb, and I don't need to use i...
# cfml-general
d
I'm sure I'm being dumb, and I don't need to use isValid() for these, but can someone tell me why these are both false?
Copy code
#isValid("regex", "c", "a-e")#
#isValid("regex", "123", "0-9+")#
a
I assume you want ranges not literals?
🤘 1
@Dave Merrill ^
d
Yeah. Doh. I knew it was a temporary blind spot. I actually do know how regexes work 🙂 Caffeine...
1
That's even what I wrote in my actual code where I used reFind() instead.
w
i've never used isValid("regex"). is there any compelling reason to do so vs the other regex BIFs?
d
Not as far as I know, which is why I used reFind() in my actual code. I was just curious about isValid() since I hadn't used it.
✔️ 1
a
It is more readable it's clear that you're checking it's a valid value, whereas reFind > 0 is a bit more verbose, so that would be a reason I can think of to use it (I don't think I ever have though!)
I guess you could also make it dynamic, so the rules are defined in an array of structs and then you could loop though and do
isValid( rule.type, myvalue, rule.pattern )
or something
c
How about:
Copy code
#isValid("regex", "c", "[a-e]+")#
#isValid("regex", "123", "[0-9]+")#
You need to add the
character class
square brackets to get a
true
result. The regex you have written is indeed
false
. https://trycf.com/gist/78d477dacdadea35c53a18c5c8c3fa30/lucee5?theme=monokai