I have a text box on a web page where I am allowing users to enter text. The maximum that can be entered is 500 characters so when the user clicks submit this validation works. The validation works, but the problem is that when the user enters a character such as a directional quote (') it is counted as more than one character. So actually when only 500 characters are entered the user receives an error because it is counting characters such as the directional quote to be more than a single character. How can this be avoided for such cases? I am not able to increase the character limit to anything over 500.


Try this,
int length = strVal.getBytes("UTF-8").length;
and then do your validation.