6 Replies Latest reply on Aug 3, 2007 7:31 AM by (Jim_Q_Smith)

    tNG_FormValidation Regular Expression help...

      Hi -
      I am having trouble getting a regular expression to work in my application. I am trying to validate a user's input into a field that will control a directory name on a Unix environment, so I don't want any spaces or special characters. Basically, the only thing a user should be allowed to enter are a-z, A-Z, the underscore (_) and 0-9. Using all sorts of regex testers, I came up with ^[a-zA-Z0-9_]+$

      However, this does not work. It is saying that input which should be valid (such as "somedirectoryname") is invalid. Any thoughts?
        • 1. Re: tNG_FormValidation Regular Expression help...
          Günter Schenk Level 4
          Hi,

          this regex as such should work -- and always has for me with ADDT. Just wondering - is this a regular text field or a multi-line text area ?

          Out of interest -- would this version work ? \A[a-zA-Z0-9_]+\z

          One hint though: ADDT´s "internal" regex rendering engine will always convert to lower case, means your upper case criteria (A-Z) will be ignored.

          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: tNG_FormValidation Regular Expression help...
            Level 1
            Here is the complete code for the form validation portion of my application...perhaps I am doing something wrong.

            // Start trigger
            $formValidation = new tNG_FormValidation();
            $formValidation->addField("series_title", true, "text", "", "", "255", "");
            $formValidation->addField("series_description", true, "text", "", "", "255", "");
            $formValidation->addField("series_summary", false, "text", "", "", "4000", "");
            $formValidation->addField("series_subtitle", false, "text", "", "", "255", "");
            $formValidation->addField("series_author", true, "text", "", "", "255", "");
            $formValidation->addField("series_short_name", true, "regexp", "^[a-zA-Z_0-9]+$", "", 255, "You have used an illegal character. Only alphanumeric characters and
            underscores are permitted.");
            $tNGs->prepareValidation($formValidation);
            // End trigger

            This code does not work; it seems to reject any input, regardless of whether it is a number or a word.
            • 3. Re: tNG_FormValidation Regular Expression help...
              Günter Schenk Level 4
              well,

              the regex that always used to work for me, is a little different:

              ^[a-zA-Z0-9_] *$

              does this one work for you ?

              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: tNG_FormValidation Regular Expression help...
                Level 1
                I just tried it, and no, it didn't work. It should though. Is it possible there is something else wrong with the code? Here is my complete form validation trigger:

                // Start trigger
                $formValidation = new tNG_FormValidation();
                $formValidation->addField("series_title", true, "text", "", "", "255", "");
                $formValidation->addField("series_description", true, "text", "", "", "255", "");
                $formValidation->addField("series_summary", false, "text", "", "", "4000", "");
                $formValidation->addField("series_subtitle", false, "text", "", "", "255", "");
                $formValidation->addField("series_author", true, "text", "", "", "255", "");
                $formValidation->addField("series_short_name", true, "regexp", "^[a-zA-Z0-9_]*$", "", 255, "You have used an illegal character. Only alphanumeric characters and underscores are permitted.");
                $tNGs->prepareValidation($formValidation);
                // End trigger
                • 5. Re: tNG_FormValidation Regular Expression help...
                  Jim:<br /><br />I went back and looked at some form validation I had added with InterAKT versions. Since I'm assuming the functionality with ADDT form validation is the same, you should see if this helps:<br />When entering a RegEx into the ADDT Form Validation dialog box, it would be entered like this:<br /><b>^[a-zA-Z]*$</b><br />but, if I then go into code view in DreamWeaver, I see that the code is generated so as to escape any special characters, so the above is changed to this:<br /><b>^[a-zA-Z]*\$</b> (Note the backslash to escape the '$' character)<br /><br />I noticed your code view is <not> escaping the '$'
                  • 6. Re: tNG_FormValidation Regular Expression help...
                    Level 1
                    Actually, I figured it out. The reason none of the regular expressions were working was that in the line:

                    $formValidation->addField("series_short_name", true, "regexp", "^[a-zA-Z0-9_]*$", "", 255, "You have used an illegal character. Only alphanumeric characters and underscores are permitted.");

                    The "max_characters" value (255) is not surrounded with quotation marks, as it should be. This was causing all regular expressions to function different than expected. As soon as I added the quotation marks around that value, everything works to perfection now.

                    Thanks for your help!