2

I have a following regex but it doesnt seem to work as expected.

I want one lowercase letter, one uppercase letter, one digit or one special character.

The length should be minimum 8 char.

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

Can anyone help please

Coder
  • 3,090
  • 8
  • 49
  • 85
  • possible duplicate of [Complex password Regular expression](http://stackoverflow.com/questions/3466850/complex-password-regular-expression) – damienc88 Dec 19 '13 at 01:08

2 Answers2

2

I see two problems. You have a double backslash in front of your digit specifier - make it a single. Also you don't have an expression for "special characters". I have added an expression to include some special characters - you can adapt that to your need (be careful - some have special meaning, for example -).

Demonstration at http://regex101.com/r/kM5xW6

Expression (updated to reflect "one digit OR one special character"):

(^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*_0-9]).*$)

This requires at least 8 characters, a lower case letter, an upper case letter, and a character from the list !@#$%^&*_0-9 (which is "one of the special characters or a digit between 0 and 9).

Floris
  • 45,857
  • 6
  • 70
  • 122
1

a little more efficient pattern = ^(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*_0-9])(.{8,})$ Demo

alpha bravo
  • 7,838
  • 1
  • 19
  • 23