!isValid('regex', 'Merholtz', '[A-Za-z-]') is returning true

!isValid('regex', 'Merholtz', '[A-Za-z-]')

Attempting to use the function above, it is returning true, when it should be false. I attempted to try this with a CF2021 engine as well and got the same result. Am I missing something?

Lucee Version: 5.xx

It would appear the regex needs to match the entire string. Try this

isValid('regex', 'Merholtz', '[A-Za-z-]*')

Cheers, that was it. Need more practice with Regex I guess. Thank you!

I don’t use ACF - but if you’re seeing differences in REGEX behaviour between ACF and Lucee…

Lucee has a “RegEx” setting in the Administrator.
So you can choose between “Legacy” (Perl 5 implementation of RegEx
And “Modern” - which is Java’s implementation of Regular Expressions.
Perhaps, alternating to the “other” option - to what you currently have set, might see your ACF RegEx - working identically in Lucee?

To be clear, the OP was reporting the same behavior on both CF engines.

I completely misread that… I thought it was working on ACF - but not Lucee…!

1 Like