Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at CFUNITED 2009 (Lansdowne, VA) with: Ray Camden

ColdFusion CFParam Regex Validation Tests Whole Value

By Ben Nadel on
Tags: ColdFusion

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.




Reader 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.

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.