Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a regular expression that requires 4 characters and no spaces?

I am trying to make the user input exactly 4 characters with no spaces... here's what I have:

.[^\s]{4}

but everything I enter says that it didn't match the regex...

Where am I going wrong?

like image 511
Matt Avatar asked Nov 27 '22 10:11

Matt


1 Answers

Why is there an extra . in front? That will match a separate character before your "four non-spaces" get counted.

You probably also want to bind it to the beginning and end of the string, so:

^[^\s]{4}$
like image 77
VoteyDisciple Avatar answered Dec 05 '22 02:12

VoteyDisciple