Is there an easy way to limit the number of characters allowed in a textbox.

I know I can count characters but I am looking at something like format where I can specify the format which limits the number of characters. In the old days I used to do like '#######'(not in VB) and that will only allow the same number of characters.

Currently I am using Regex but this only returns an error, if i need a number it only returns an error without knowing whether the problem is the format or the length.