Text UtilitiesLesson 123Free preview
Character Counter
This lesson is part of Web Developer Tools · All levels
Summary
The character counter counts the number of characters in a text, sometimes separated between by spaces, without spaces, letters, numbers, and bytes. This is important for form limits, social media, or database validation. Note that the length in bytes can vary from the number of characters, especially for emoji and non-ASCII letters. Use a method of calculation that conforms to the rules of the destination platform.
Key points
- Character length and byte length are two different metrics
- Str.length in JavaScript counts the UTF-16 unit, not always characters
- Spread or Array.from is more accurate for counting emoji
- Calculate with or without spaces as needed
- Unicode normalization can change the number of code points
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.