How to restrict the entry in html field based on the actual length

207 views Asked by At

If i am getting a string of any language(English, Japanese, Chinese, French..) to a text field in my html file, how i can restrict the entry based on the actual length.

For example: My html tag looks likes below:

<input type="text" name="id_details" maxlength="255" size="35" id="id_details" />

And in the back-end cpp file i am accessing this form value as follow.

int length = strlen((char *)from->value.id_details);

If i am entering a Chinese string of 100 characters in the html field then in the back-end i am getting the length as 300(100 * 3) because 1 Chinese character is equal to 3 bytes.

So i need to restrict the entry of any language to the html field based on the byte length i.e, if we are entering a Chinese string then we can only enter 85 characters (255 / 3 --> maxlength / 3) and for English we can enter 255 characters and for Japanese we can enter nearly 127 (255 / 2 --> 1 Japanese character is equal to 2 byte) like wise.

0

There are 0 answers