Mert
Mert

Reputation: 6572

regex doesnt work

I am trying to create a regex only text space accepted and maximum 35 character.

^[a-zA-Z\s]*.{1,35}$ 

Upvotes: 1

Views: 63

Answers (1)

Mathieu Paturel
Mathieu Paturel

Reputation: 4500

if I understand you right, here's what you need

^[a-zA-Z\s]{1,35}$ 
  • [a-zA-Z\s]: whichever characters that is a letter or a space (newlines included, you might want to change that out: the \s is what you could replace with )

The problem with your regex

^[a-zA-Z\s]*.{1,35}$
  • * means 0 times or more the pattern that I wrote before. In this case, [a-zA-Z\s].
  • . means everything except \n (a newline). And it was this pattern that had to be repeated at least once, and at the most, 35 times.

Upvotes: 3

Related Questions