tags:

views:

32

answers:

3

Hi, I need a regular expression for my rails application for password field. any character or number or symbols is allowed except space.

Thanks!

+1  A: 

All except spaces, do you need to narrow the results a bit more than this?

/[^ ]+/
BrunoLM
User could paste in a tab character. I know the OP didn't say "whitespace," but I think that's the intent.
Jay
+4  A: 

At least one character, no max:

^\S+$

The \S switch excludes any whitespace (space, tab, etc.).

Jay
A: 

Without minimum length (or rather, with minimum length 1):

^\S+$

With minimum length 8:

^\S{7}\S+$
or, if your regex engine supports it (don't know why it wouldn't):
^\S{8,}$
JAB
The first one has a minimum length of 1 and these ignore the requirement to exclude spaces.
Jay
@Jay: Yeah, I fixed the first while you were commenting and just fixed the second. Got `.` mixed up with `\w`/`\S` for a moment.
JAB
Okay, but `\w` still doesn't fit the bill, I'm afraid. OP asks for "any character or numbers or symbols" which would include punctuation. `\w` is only alpha, numeric, and underscore.
Jay
@Jay: Again, corrected that while you were commenting.
JAB