I need to make a string starts and ends with alphanumeric range between 5 to 20 characters and it could have a space or none between characters. /^[a-z\s?A-Z0-9]{5,20}$/ but this is not working.
EDIT
test test -should pass
testtest -should pass
test test test -should not pass
You can’t do this with traditional regex without writing a ridiculously long expression, so you need to use a look-ahead:
This says, make sure there are between 15 and 20 characters in the match, then match
/\w+ \w+/Note I used \w for simplification. It is the same as your character class above except it also accepts underscores. If you don’t want to match them you have to do: