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,601
  • 24
  • 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,247
  • 1
  • 17
  • 21
  • 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
  • 47,968
  • 31
  • 142
  • 252
0
^(?!.*\s.*)(?=.*\d.*\d)(?=.*[$/@:?{~!^`\[\]]{1,}).{8,}$

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

Captain
  • 2,148
  • 15
  • 13
0

here is my suggestion:

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

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

Tim.Tang
  • 3,158
  • 1
  • 15
  • 18
0
 (?!.*?\s+.*?)

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

vks
  • 67,027
  • 10
  • 91
  • 124