James Mathieson
James Mathieson

Reputation: 439

Regex match strings less than 150 chars in length

I've been having no luck with a simple regex to match strings with 150 or less characters to alert my users of descriptions being too short.

These description values can contain any character/number with no specific pattern. Can someone with regex knowledge lend a hand?

Upvotes: 21

Views: 46366

Answers (2)

Eric Hein
Eric Hein

Reputation: 351

Regex is overkill, just check the length of the string.

Upvotes: 2

Cairnarvon
Cairnarvon

Reputation: 27822

^.{0,150}$

This will match a whole string containing between 0 and 150 (inclusive) of any character. Though regular expressions are probably the wrong tool for this job.

Upvotes: 51

Related Questions