JSFiddle - React, Tailwind, and code Playground
by Tan
HTML
<h2>JavaScript Validation</h2>
<p>Please input a number: £ 2,500,000</p>
<input id="numb">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
JavaScript
function myFunction() {
// Get the value of the input field with id="numb"
const x = document.getElementById("numb").value;
let s2 = "";
var text = "";
for (const char of x) {
if (!isNaN(char) || char === " " || char === "£" || char === "," ) {
text = "good";
}
else {text = "bad";break;}
}
document.getElementById("demo").innerHTML = text;
}