title: String length differs from Javascript to Java code
body: <p>I've got a JSP page with a piece of Javascript validation code which limits to a certain amount of characters on submit. I'm using a <code>&lt;textarea&gt;</code> so I can't simply use a length attribute like in a <code>&lt;input type="text"&gt;</code>.</p>
  
  <p>I use <code>document.getElementById("text").value.length</code> to get the string length. I'm running Firefox 3.0 on Windows (but I've tested this behavior with IE 6 also). The form gets submitted to a J2EE servlet. In my Java servlet the string length of the parameter is larger than 2000!</p>
  
  <p>I've noticed that this can easily be reproduced by adding carriage returns in the <code>&lt;textarea&gt;</code>. I've used Firebug to assert the length of the <code>&lt;textare&gt;</code> and it really is 2000 characters long. On the Java side though, the carriage returns get converted to UNIX style (<code>\r\n</code>, instead of <code>\n</code>), thus the string length differs!</p>
  
  <p>Am I missing something obvious here or what ? If not, how would you reliably (cross-platform / browser) make sure that the <code>&lt;textarea&gt;</code> is limited. </p>