If you want to count empty spaces also, check the length of the textbox's text. You can try below javascript code:
document.getElementById("txt").value.length
You can also try JQuery:
$("#txt").val().length
If you don't want to consider spaces then you need to trim the text before checking for length. To trim text in javascript you can use solution#2 and for JQuery you can do it like this:
$.trim($("#txt").val()).length
Here "txt" is the client-id of the textbox control.
Hope that helps!