JSFiddle - React, Tailwind, and code Playground
by Swami
HTML
<a href="https://code2care.org">Example by Code2care.org</a>
<br/>
<h1>
Check if inputed text is a number using Regex
</h1>
<input type="text" id="text">
<button type="button" onClick="checkisNumber()">Check</button>
<div id="result"></div>
JavaScript
function checkisNumber() {
var no = document.getElementById("text").value;
var isNoRegex=/^\d*(\.)?(\d{1,})?$/;
if(!no.match(isNoRegex)) {
document.getElementById("result").innerHTML = no + " is not a number";
} else {
document.getElementById("result").innerHTML = no + " is a number";
}
}