For example, this string ought to return a length of 10:
Code: Select all
One
TwoCode: Select all
<script type="text/javascript">
function countMe(obj) [obj = the textarea]
{ // figure out how many characters have been entered
if(!obj) return;
var iLength = obj.value.length; // characters used (including line breaks as one char each)
var aBR = obj.value.match(new RegExp("(\\n)")); // count line breaks
var iBR = aBR ? aBR.length : 0; // if no line breaks found, return 0, else return count
var iUsed = iLength + iBR; // the number of characters used should count line breaks twice
return; // exit
}
</script>Any ideas?