1

Password must contains minimum of 8 symbols.

min 2 digits in any order,

min 1 special in any order character and

must not allow whitespaces.

I have something like this:

(?=.*\d.*\d)(?=.*[$/@:?{~!^`\[\]]{1,}).{8,}

UPD solution:

(?=[^\s]*\d){2}(?=[^\s]*[$/@:?{~!^`\[\]]){1,}[^\s]{8,}
ivamax9
  • 2,563
  • 22
  • 33

5 Answers5

1

I would change the . into \S, if your language supports negated classes

(?=\S*\d){2}(?=\S*[$/@:?{~!^`\[\]]){1,}\S{8,}

or into [^\s], if it does not

(?=[^\s]*\d){2}(?=[^\s]*[$/@:?{~!^`\[\]]){1,}[^\s]{8,}
Roberto Reale
  • 4,177
  • 1
  • 15
  • 20
  • 1
    @Chase Since `\S{8,}` will whatever check for whitespaces, no need to use `\S` in the lookaheads. The `^` and `$` anchors are also missing. – sp00m Aug 20 '14 at 09:45
1

Here is another one:

^(?=(?:.*\d){2})(?=.*[$/@:?{~!^`\[\]])\S{8,}$

Regular expression visualization

Debuggex Demo

sp00m
  • 46,243
  • 25
  • 134
  • 239
0
^(?!.*\s.*)(?=.*\d.*\d)(?=.*[$/@:?{~!^`\[\]]{1,}).{8,}$

Anchoring it to the start and end, with a negative lookahead for the whitespace

Captain
  • 1,998
  • 13
  • 13
0

here is my suggestion:

^(?!\d+$)(?![$/@:?{~!^`\[\]]+$)[$/@:?{~!^`\[\]\d]{8,}$

NOTES: you need find another way to check at least 2 digits

Tim.Tang
  • 3,118
  • 1
  • 14
  • 17
0
 (?!.*?\s+.*?)

Just add this to your existing regex.A negative lookahead detecting one or multiple spaces.

vks
  • 65,133
  • 10
  • 87
  • 119