开发者

Regular expression for password validation that doesn't allow spaces [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_运维问答

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 8 years ago.

Improve this question

I need a regular expression for my Ruby on Rails application for the password field.

Any character or number or symbols is allowed except space.


If this is client-side validation in Javascript (or any language other than Ruby), this expression will match a string with no whitespace (\S) at least one character (+), no max:

^\S+$

Ruby is the only language that uses multi-line mode by default, so the start-of-line ^ and end-of-line $ behave differently (they match once per input, no matter how many lines). So, if you are validating the input in Ruby, you'd need to use \A for start-of-line and \Z for end-of-line.

\A\S+\Z


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

/[^ ]+/


This is 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,}$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜