Last active
October 6, 2020 15:53
-
-
Save jamilservicos/1d2e2dceb1529fe2e27b5fb18f30d037 to your computer and use it in GitHub Desktop.
simple example of uppercase, lowercase and capitalize text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
simple example to capitalize | |
*/ | |
function capitaLize() { | |
const textbox = document.getElementById("text-box"); //textarea | |
const textresult = document.getElementById("text-result"); //result element "<pre>"; | |
if ((textbox) && (textbox.value) && (textbox.value.toString().trim().length > 0)) { | |
textresult.innerText = ""; | |
const str = textbox.value.toString().trim().toLowerCase(); //turns everything to lowercase | |
const length = str.length; | |
if (length > 0) { | |
textresult.innerText = str.toString().replace(/\S+/g, words => { //separate by word blocks | |
return words.charAt(0).toUpperCase() + words.substr(1); //to uppercase first character | |
}); | |
return true; | |
} | |
} | |
// | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
simple example to lowercase | |
*/ | |
function lowerCase() { | |
const textbox = document.getElementById("text-box"); //textarea | |
const textresult = document.getElementById("text-result"); //result element "<pre>"; | |
if ((textbox) && (textbox.value) && (textbox.value.toString().trim().length > 0)) { | |
textresult.innerText = ""; | |
const str = textbox.value.toString().trim(); | |
const length = str.length; | |
if (length > 0) { | |
textresult.innerText = str.toString().toLowerCase(); | |
return true; | |
} | |
} | |
// | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
simple example to uppercase | |
*/ | |
function upperCase() { | |
const textbox = document.getElementById("text-box"); //textarea | |
const textresult = document.getElementById("text-result"); //result element "<pre>"; | |
if ((textbox) && (textbox.value) && (textbox.value.toString().trim().length > 0)) { | |
textresult.innerText = ""; | |
const str = textbox.value.toString().trim(); | |
const length = str.length; | |
// | |
if (length > 0) { | |
textresult.innerText = str.toString().toUpperCase(); | |
return true; | |
} | |
} | |
// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment