ColdFusion CFParam Regex Validation Tests Whole Value
Posted November 14, 2008 at 8:49 AM
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:
Launch code in new window » Download code as text file »
- <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:
Launch code in new window » Download code as text file »
- <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.
Download Code Snippet ZIP File
Post Comment | Ask Ben | Permalink | Other Searches | Print Page
Newer Post
Ask Ben: Iterating Over An Array With jQuery
Older Post
Ask Ben: Hiding Customer-Specific Image Paths
Reader Comments
There are no comments posted for this web log entry.



