M
M
Mariik2018-07-16 13:35:25
Regular Expressions
Mariik, 2018-07-16 13:35:25

How to prevent spaces in a regular expression?

Hello.
In general, you need to test a string with a regular expression for:
1. Length 6-16
2. At least 1 uppercase character
2. At least 1 lowercase character
3. At least 1 digit
4. Optional special characters.
this is what I came up with:

/(?=^.{8,16}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/

But this regex will skip spaces...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Dart, 2018-07-16
@gobananas

Spaces prevent this [^\s]
https://regex101.com/r/Ta5coG/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question