Free Online Word Count Tool and Online Character/Letter Count Calculator

Count characters after text trim - removing preceding and trailing white spaces. Count characters after removing duplicate white spaces.

The word counter and character/letter counter gives real-time results and counts appears as you type.
       




JQuery and JavaScript examples how to calculate number of words and letters in a text, how to trim the text, how to remove duplicate white spaces and how to replace line breaks with spaces.


// Calculate number of characters and words in a text		
function calculate() {
	var newText=$.trim(($('#txtCounter').val()).replace(/(\r\n|\n|\r)/gm,' ').replace(/\s{2,}/g, ' '));
	var words = newText.split(' ');
	var numberOfWords=words.length;
	if (newText.length == 0)
	numberOfWords=0;
	var characters = $('#txtCounter').val();
	$('#result').html("Words: "+numberOfWords+"        Characters/Letters: "+ characters.length);
}

// Trim the text - remove preceding and trailing spaces
function trimTxt() {
	var newText=$.trim($('#txtCounter').val());
	$('#txtCounter').val(newText);
	calculate();
}

// Remove multiple white-spaces
function removeDuplicateSpaces() {
	var newText=$.trim(($('#txtCounter').val()).replace(/\s{2,}/g, ' '));
	$('#txtCounter').val(newText);
	calculate();
}

// Replace new lines (line breaks) with white space
function removeLineBreaks() {
	var newText=$.trim(($('#txtCounter').val()).replace(/(\r\n|\n|\r)/gm,' ').replace(/\s{2,}/g, ' '));
	$('#txtCounter').val(newText);
	calculate();
}

// Clear text in text area
function clearTxt() {
	$('#txtCounter').val("");
	calculate();
}			
			
			


You can use this tool to minify JavaScript and CSS. Minifying JS and CSS makes your pages smaller and load faster - SEO friendly.