0

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.

Sams
  • 1
  • 1
  • Why the 100 byte limit, instead of a 100 character limit on the backend? – meskobalazs Sep 18 '20 at 14:55
  • In the backend we are checking whether length is greater than 255 and if so we are throwing a bad request, but user is not aware what is happening. So we got the request to handle this issue from the frontend itself. – Sams Sep 20 '20 at 12:23
  • In the backend how we can do a character check? – Sams Sep 20 '20 at 12:26

0 Answers0