0

I need regex for a password that has:

  • at least one non letter or digit character.
  • at least one lowercase ('a'-'z').
  • at least one uppercase ('A'-'Z').

I need it for HTML pattern attribute.

I tried this:

"^[a-zA-Z0-9]*$"

but it accepts only a, for example. also this:

"[A-Za-z0-9]"

accepts one character

mshwf
  • 7,009
  • 12
  • 59
  • 133
  • Try doing 3 different regex's, one for each instance: number, uppercase letter, lowercase letter – ganders Mar 14 '17 at 16:01
  • This has been asked many times on SO. Just use the search function! – Fallenhero Mar 14 '17 at 16:06
  • 1
    You can see same question and answer from [this link](http://stackoverflow.com/questions/19605150/regex-for-password-must-be-contain-at-least-8-characters-least-1-number-and-bot?answertab=oldest#tab-top) – Hakan Altınbaş Mar 14 '17 at 16:09
  • There is even an example on w3schools on the page for validations using the pattern attribute. `(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}`, change `{8,}` to `+` if you don't care about length - https://www.w3schools.com/tags/att_input_pattern.asp – rvalvik Mar 14 '17 at 16:11

1 Answers1

1

Regex: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$/gm

Regex demo

Regex: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]{10}$/gm

Regex demo for specific length

Sahil Gulati
  • 15,028
  • 4
  • 24
  • 42