Regular Expression To Limit Length Of Characters

A regular expression to limit the length of characters (between x and y characters long).

/^(.|\n){0,18}$/

Matches:

  • 0
  • abc
  • 123456789012345678

Non-matches:

  • 1234567890123456789
  • abcdefghijklmnopqrs