user3354908
user3354908

Reputation:

Regex for password must contain at least 8 characters, at least 1 number, letters and special characters

I need a regular expression which should have at least one numeric character, both uper and lower case letters allowed, special characters also allowed I am using this expression

/^.*(?=.{6,10})(?=.*\d)(?=.*[a-zA-Z]).*$

but it is not valid for max characters 10.

Upvotes: 3

Views: 4560

Answers (3)

Dardy
Dardy

Reputation: 1

^(?=.{8,})(?=.+\d)(?=.+[A-Za-z])(?=.+\W).*$
  • 8 char min
  • 1 numeric min
  • 1 letter min
  • 1 special char min

Upvotes: 0

hwnd
hwnd

Reputation: 70732

The following regular expression will limit your length and allow special characters.

^(?=.*\d)(?=.*[a-zA-Z]).{6,10}$

Upvotes: 2

Avinash Raj
Avinash Raj

Reputation: 174776

Seems like you want something like this,

^(?=.*\d)(?=.*?[a-zA-Z])(?=.*?[\W_]).{6,10}$

The above regex would allow 6 to 10 characters only. And it also checks for at-least one digit, upper or lowercase letter and at-least one special character (characters other than letters and numbers).

Upvotes: 2

Related Questions