Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password Regex Validation: Preventing Spaces

Tags:

c#

regex

Okay, so I'm trying to adhere to the following password rule:

Must be 6 to 15 characters, include at least one lowercase letter, one uppercase letter and at least one number. It should also contain no spaces.

Now, for everything but the spaces, I've got:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,15}$

Problem is, that allows spaces.

After looking around, I've tried using \s, but that messes up my lowercase and uppercase requirements. I also seen another suggestion to replace the * with a +, but that seemed to break the entire thing.

I've created a REFiddle if you want to have a live test.

To clarify, this is a client requirement unfortunately, I'm never usually this strict with passwords.

like image 627
mattytommo Avatar asked Sep 27 '13 10:09

mattytommo


1 Answers

How about:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)\S{6,15}$

\S stands for any NON space character.

like image 110
Toto Avatar answered Sep 20 '22 17:09

Toto