1

If inputted text doesn't match with my pattern:

^(\b[\n]\w*\s*)+$

Which is if finding \n character in the inputted text then the text will not be validated, but I want to add min and max length to all whole string. I expect if the text doesn't match the pattern and string length lower than 3 and exceed 10 then it will not be validated, I know this following pattern is not correct but at least I'm trying to modify it like this:

^(\b[\n]\w{3,10}\s*)+$

For sample:

FrogFrog
FrogFrog <- it won't validated because has \n and exceed 10

Frog
Frog <- it won't validated because has \n

FrogFrogFrog <- it wont't validated because exceed than 10

FrogFrogFr <- it is valid because no \n character and not exceed than 10

Any correction or suggestions?

Guinglain
  • 15
  • 5
  • It looks as though all you need is `^.{3,10}$`. Or, if there can only be letters, digits, or `_`, `^\w{3,10}$`. Please share your code if it still does not work and you need help. – Wiktor Stribiżew Nov 03 '20 at 08:26

2 Answers2

0

try this regex :

^([\w\s]{3,10})(?!\n)$
aziz k'h
  • 775
  • 6
  • 11
0

You might start the match with a word character to match at least a character at the start.

Then repeat 2-9 times matching either a word character, space or tab using a character class and end the pattern with \z to assert the end of the string.

^\w[\w \t]{2,9}\z

For example a regex demo with match and a regex demo with no match.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70