OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Print valid or invalid input in console based on textArea.value

  • Thread starter Thread starter Ubaid Mirza
  • Start date Start date
U

Ubaid Mirza

Guest
I am trying to build a function in JavaScript that prints "valid input" in console if all characters in the textbox are other than alphabets (upperCase, lowerCase). But if any of character in the textbox is alphabet then it prints "valid input". I used a button to invoke this function.

Test case for more understanding: "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 confused about logic building of this problem.

Firstly I go with regular expression but did'nt understood how to implement it in this problem. Still stucked.

Code:
function capCaseHandle() {
        const allCharRegExp = /[\w]+/;
        let text = document.getElementById("textArea");
        if (allCharRegExp.test(text)) {
                        console.log("Valid Text");
        }
        else {
            console.log("Invalid Text");
        }
    }

I tested this function but the function itself is invalid.

<p>I am trying to build a function in JavaScript that prints "valid input" in console if all characters in the textbox are other than alphabets (upperCase, lowerCase). But if any of character in the textbox is alphabet then it prints "valid input". I used a button to invoke this function.</p>
<p>Test case for more understanding:
"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)</p>
<p>I am confused about logic building of this problem.</p>
<p>Firstly I go with regular expression but did'nt understood how to implement it in this problem. Still stucked.</p>
<pre><code>function capCaseHandle() {
const allCharRegExp = /[\w]+/;
let text = document.getElementById("textArea");
if (allCharRegExp.test(text)) {
console.log("Valid Text");
}
else {
console.log("Invalid Text");
}
}
</code></pre>
<p>I tested this function but the function itself is invalid.</p>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top