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?
By combining the interval quantifier with the surrounding start- and end-of-string anchors, the regex will fail to match if the subject text's length falls outside the desired range.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
^.{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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With