RegEx for Multi-Words Without Numbers and Any Special Characters

Okay, you want to validate the text:

This regex seems to be doing what you want:

^(?=.{1,50}$)(\w+[,.!?&']?\s?)+$

It will accept a word followed by an optional punctuation and an optional space.

The ^(?=.{1,50}$) will control the character limit, here the limit is at least 1 character and max 50 characters
The rest is the validation of the text.

It will accepts things like:
I want to finish.
I am great! How are you?
I don’t care

But it does not accept:

I could really #*!$ that guy

WARNING! This is really a too simple way to avoid spamming and the users will pretty fast learn a way to get past it.

Leave a Comment