Home > Net >  Regex for text field with apostrophes
Regex for text field with apostrophes

Time:01-02

I've never used regex. Basically I'm building a web app and in a form the user can enter a short description of himself in a field. This means only words separated by spaces. For now I have this regex:

^[a-zA-Z ]*$

but I want to allow 2 things: the use of apostrophes too, so I can write: Cosi che d'ora in poi

and that the maximum description, between words and whitespace, is maximum 40 characters

CodePudding user response:

You can try https://regex101.com/

For your example this should work:

^[a-zA-Z ']*$

Considering the whitespacees you should check for

"' ' * 40"
  • Related