2 Replies Latest reply on Jan 26, 2009 8:44 AM by Newsgroup_User

    RegEx Help

    Balance Level 1
      I have a "UserID" field that can't have spaces or backslashes in it. I've put together the following reg ex but it doesn't seem to work and I'm not sure why. In other words, even if I type "jdoe$" (which does not have a space or backslash) I still get the pop-up from my cfinput. Can someone please shed some light?

      <cfinput type="text" name="UserID" size="45" required="yes" message="Please make sure the UserID does not have spaces or backslahes." validate="regular_expression" pattern="[[:space:]\\]">
        • 1. Re: RegEx Help
          Level 7
          > I have a "UserID" field that can't have spaces or backslashes in it. I've put
          > together the following reg ex but it doesn't seem to work and I'm not sure why.
          > In other words, even if I type "jdoe$" (which does not have a space or
          > backslash) I still get the pop-up from my cfinput. Can someone please shed some
          > light?
          >
          > <cfinput type="text" name="UserID" size="45" required="yes" message="Please
          > make sure the UserID does not have spaces or backslahes."
          > validate="regular_expression" pattern="[[:space:]\\]">

          Your regex pattern here has to match what you DO want, not what you don't
          want. I'm also not sure JS regexes support posix-styled character classes.

          I suspect you haven't thought through your requirement here. In saying
          simply that the userid can't have spaces or backslashes (and approaching
          the regex that way), you're implying that *any other character* is OK.

          So this userid would be just fine: !"£$%^&*()_-+=. I has no spaces or
          backslashes in it.

          --
          Adam
          • 2. Re: RegEx Help
            Kronin555 Level 1
            The pattern needs to match what's valid, not what's invalid.
            See:
            http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=validateData_09.html#117 6093
            "The validation succeeds only if the user input matches the pattern."

            [^\s\\]

            This will match any strings that don't contain whitespace (spaces, tabs, form feeds, line feeds) and don't contain a backslash.