Skip to main content
Ben Nadel at CFUNITED 2010 (Landsdown, VA) with: Michael Evangelista and Avery Shumway
Ben Nadel at CFUNITED 2010 (Landsdown, VA) with: Michael Evangelista Avery Shumway

ColdFusion CFParam Regex Validation Tests Whole Value

By
Published in Comments (2)

This is a minor but important fact that I just realized. ColdFusion's CFParam tag regular expression validation tests its pattern on the entire value in question. This means that you don't have to worry about partial string matches. What this means is that you never need to use the start (^) and end ($) delimiters as these are applied implicitly. So, for example, the CFParam tag:

<cfparam name="name" type="regex" pattern="naomi" />

... is really implicitly applying the pattern:

^(naomi)$

This is good to know, as I had previously been using the start and end line delimiters. But, this also lead to a new realization - pattern flags don't have to be the very first thing in a regular expression pattern. These patterns are case-sensitive, so you if you wanted to make it case-insensitive, you would have to add the "i" flag:

<cfparam name="name" type="regex" pattern="(?i)naomi" />

Of course, this is actually applying the pattern:

^((?i)naomi)$

I used to think that the pattern flags (?i) had to be the very first thing in the pattern, but apparently not (and the RegEx Coach confirms this as well).

So again, this is really minor, but an important point to understand.

Want to use code from this post? Check out the license.

Reader Comments

7 Comments

Thanks again Ben! Saved me all kinds of frustration finding my "order by" query paramming helper broke when enforcing uppercase column names for Oracle... all I needed was the (?i) case insensitivity attribute on my regex.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel