RegEx for a string of length 0-2

Use the following regex:

^[0-9]{0,2}$

You almost had it — the ^ and $ characters are anchors that match the beginning and end of the string, respectively.

For a more in-depth discussion on anchors, see here:

[Anchors] do not match any character at all. Instead, they match a position before, after or between characters. They can be used to “anchor” the regex match at a certain position.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)