5 Replies Latest reply on Jan 2, 2008 9:22 AM by Newsgroup_User

    CFPARAM Problem

    Fusionneer
      Hi All,

      Does anyone know how to get POSIX style character classes working in a CFPARAM wiith type="regex"? E.G.]

      <cfparam name="frustrate" type="regex" pattern="[[:print:]]" default="">

      This throws an error when I pass in any value.

      . Invalid parameter type.The value does not match the regular expression pattern provided. The specific sequence of files included or processed is: ......

      The only regular expression classes I can get working are the usual ASCII ones ([a-z] etc) but I need to validate UTF-8 characters as well. I've searched the Adobe forums, some CF blogs and of course I RTFM but I can't see any way of doing this without writing out the character codes longhand which is not only a maintenance issue but would then require far more testing just to ensure there are no ommissions. If anyone can help, it would be appreciated.
        • 1. Re: CFPARAM Problem
          Level 7
          Fusionneer wrote:
          > Does anyone know how to get POSIX style character classes working in a CFPARAM
          > wiith type="regex"? E.G.]

          :print: is a valid char class for cf regex & seems to work as expected w/the cf
          regex functions. might be something about cfparam's regex. i'm no regex expert
          but is there any difference between POSIX regex & "JavaScript regular
          expression" (which the docs say cfparam uses)?
          • 2. Re: CFPARAM Problem
            Level 7
            > of course I RTFM

            Looking @ this:
            http://livedocs.adobe.com/coldfusion/8/Tags_p-q_01.html

            The regex pattern needs to be a JavaScript compatible pattern.

            JavaScript regexes don't support Unicode, beyond \uhhhh, from what I'm
            finding.

            That sux a bit, dunnit?

            --
            Adam
            • 3. Re: CFPARAM Problem
              Fusionneer Level 1
              Thanks Adam and Paul for responding.

              The manual does indicate that only JavaScript compatible patterns will work in CFPARAM and that does indicate using the longhand Unicode syntax which doesn't suck a bit, it SUCKS A LOT!!!!

              The only way I have found to overcome the issue is to wrap my cfparam in a try/catch, use the basic JS compatible pattern eg \w , and when it throws an error do a negative test using the POSIX style class. Then if that fails I know I have a character that is unacceptable and so I can rethrow the original error. EG:

              <cftry>
              <cfparam name="FORM.houseNo" type="regex" pattern="[-a-zA-z0-9_#]+|\s{1}" default="32">
              <cfcatch type="any">
              <cfif ReFindNoCase("[^[:print:]]+",FORM.houseNo,1,"true") >
              <!--- Fail here - doesn't match ASCII Or UNICODE --->
              <cfrethrow>
              </cfif>
              </cfcatch>
              </cftry>

              Of course I then need to wrap all my individual try/catch cfparam blocks with another try / catch block just so I can pick up the rethrows.

              This is so ugly I am thinking of removing my cfparam tags altogether and just going with the regular expression checks.

              • 4. Re: CFPARAM Problem
                Level 7
                > This is so ugly I am thinking of removing my cfparam tags altogether and just
                > going with the regular expression checks.

                That's what I was going to suggest.

                if (structKeyExists(form, "houseNo") and reFind(etc))

                Remember to anchor the regex to both beginning and end of string, otherwise
                you could find embedded matches, not just complete matches.

                --
                Adam
                • 5. Re: CFPARAM Problem
                  Level 7
                  Fusionneer wrote:
                  > The manual does indicate that only JavaScript compatible patterns will work in
                  > CFPARAM and that does indicate using the longhand Unicode syntax which doesn't
                  > suck a bit, it SUCKS A LOT!!!!

                  http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform&product=12&6213=6