I am currently working on a JavaScript function that will display "valid input" in the console if all characters in a text box are non-alphabetic. However, if any alphabetic character is found in the text box, it should also display "valid input". This function is triggered by a button click.
Here are some test cases to help illustrate:
- "Lorem ipsum dolor sit amet" (valid)
- "54646475" (invalid)
- "#$#$&" (invalid)
- "Lorem ipsum 655746 dolor sit amet" (valid)
- "Lorem ipsum dolor sit #$%^ amet" (valid)
- "Lorem ipsum 7746 dolor %$^& sit amet" (valid)
I am struggling with the logic for this particular problem.
Initially, I attempted using regular expressions but I'm having trouble implementing them effectively in this scenario.
function capCaseHandle() {
const allCharRegExp = /[\w]+/;
let text = document.getElementById("textArea");
if (allCharRegExp.test(text)) {
console.log("Valid Text");
}
else {
console.log("Invalid Text");
}
}
I have tested this function but unfortunately, it appears to be invalid itself.