title: How to calculate byte length containing UTF8 characters using javascript?
body: <p>I have textbox, in which the user can enter the characters in ASCII/UTF-8 or a combination of both. Is there any API in javascript which we can calculate the length of string in bytes for the characters entered in textbox.</p>
  
  <p>Like if i enter ascii chacter let's say : mystring - the length would be calculated as 8. But when UTF8 characters are entered the characters can be 2/3/4 byte.</p>
  
  <p>lets say the character entered : i ♥ u , the length in bytes is 5.</p>
  
  <p><strong>The textbox can accept max length of 31 characters.</strong> But in case if UTF8 characters entered, it will not accept character string : i ♥ u i ♥ u i ♥ u i ♥ u i ♥ u . the length is 30.</p>
  
  <p>Can we restrict the user to enter characters not more than 31 even for UTF8 characters.</p>