limit input in field on web

How can I limit the number of input characters to a field on the web? Format works in smart client, but not on the web client. I have searched documentation and the forum, but can’t find a solution. I don’t think I should have to write a function to check the length of each field, but is that the only way?

Reg ex will work, but is there a way to show a message when the length exceeds the limit instead of just coloring the field red?

I found some references on the forum to putting INVALID_INPUT in the global error handler and that seems to be working.

Thanks