-1

I've looked and found so much information for regex. It's super well documented, but I'm clearly being an idiot, or have looked at this issue for too long!

The pattern I need to match is any number of upper case, lower case and numbers, with at least 8 characters. I don't want to accept anything else, such as non-alphanumeric characters (_ *^& etc)

My effort is

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

Sadly, when I use https://regex101.com/ this does not match any of the following

aaaaaaaa
AAAAAAAA
00000000
asdfFDSA167
#fFaf9374A
12345678
123456NBh

2 of those are valid but I don't see why I'm having issues

The end goal is to use this in the pattern attribute for input (HTML 5 input pattern="" />`)

MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120

2 Answers2

1

I believe this is what you're looking for: ^[a-zA-Z0-9]{8,}$

Or maybe this: ^[a-z]{8,}|[A-Z]{8,}|[0-9]{8,}$

The first one will match any combination of letters/numbers and the second one will only match sequences of like-characters. It's hard to tell exactly what you're looking for given the question.

EDIT: I made a mistake but fixed it

Jonathan Gray
  • 2,509
  • 15
  • 20
0

Try this :

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

DEMO

Mohammed Elhag
  • 4,272
  • 1
  • 10
  • 18