I have a working regex for when a user can enter only 1 word into a text box.
However, how can I adjust it, to allow 2,3,4,5 single words? At times, I may need to alter the code to only allow 3 words, for example that is.
Here is my regex ^([a-zA-Z_\-\.]+)$
For matching 2,3,4,5 single words
For matching 2 or 4 single words
But it fails under tests
abc.defandabc_def=( It founds two words.\bis the wrong idea with your vocabulary[a-zA-Z_\-\.]+…Okay, that’s it.
For 2,3,4,5 words
Notice that now non-alphabet symbols in the end are disallowed.