Skip to main content
Inspiring
January 26, 2009
Question

RegEx Help

  • January 26, 2009
  • 2 replies
  • 351 views
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:]\\]">
This topic has been closed for replies.

2 replies

Participating Frequently
January 26, 2009
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#1176093
"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.
Inspiring
January 26, 2009
> 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