Commit 4289ad1a authored by Ratnadeep Rajendra Kharade's avatar Ratnadeep Rajendra Kharade
Browse files

added function to calculate text length without special characters

parent d04a5a08
Pipeline #1085 passed with stages
in 9 seconds
......@@ -33,11 +33,18 @@ function toggleElement(id) {
// and sets number of characters to property textLength on inputObj
function handleTextAreaChange() {
let value = document.getElementById("manual-text-entry").value;
value = value.trim();
inputObj.text = value;
let characters = value.split(' ').join('').length;
value = removeSpecialCharacters(value);
let characters = value.length;
document.getElementById("calculatedTextCharacters").setAttribute('value', characters)
document.getElementById("calculatedTextCharacters").setAttribute('value', characters);
// function removeSpecialCharacters: removes punctuation marks and other special characters
// but allows numbers and alphabets along with language specific characters German: äöüÄÖÜß and French: ùûüÿàâæéèêëïîôœÙÛÜŸÀÂÆÉÈÊËÏÎÔŒ
function removeSpecialCharacters(str) {
return str.replace(/(?!\w|||||||||||\ÿ|||||||||||||||||||||||||\Œ)./g, '') // regex to remove special characters
.replace(/^(\s*)([\W\w]*)(\b\s*$)/g, '$2'); // regex to trim the string to remove any whitespace at the beginning or the end
......@@ -134,7 +141,7 @@ function calculateReadingTime() {
// set value to html element
var s= document.getElementById('reading-time-element');
var s = document.getElementById('reading-time-element');
s.innerHTML = x;
// display html element which shows time
let element = document.getElementById('calculate-time-element');
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment