Count textarea characters tricky issues.

Recently, from one of my projects, I faced the very interesting issues about characters count in the textarea. The purpose is to limit user inputs and had certain max character length, the max length value will be invoked from hibernate java bean column length, which will be consistency with user input and database storing. But issues occurred.