Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,940 questions

51,877 answers

573 users

How to validate input number with validation API in JavaScript

3 Answers

0 votes
<!DOCTYPE html>
<html>
<body>

<p>Enter a number between 1 to 100:</p>

<input id="input-number-id" type="number" min="1" max="100">
<button onclick="checkFunction()">OK</button>

<p id="message-id"></p>

<script>
function checkFunction() 
{
    var obj = document.getElementById("input-number-id");
    if (obj.checkValidity() == false) 
        document.getElementById("message-id").innerHTML = obj.validationMessage;
    else 
        document.getElementById("message-id").innerHTML = "Input OK";
} 
</script>
</body>
</html>



answered Jun 29, 2015 by avibootz
edited Jun 29, 2015 by avibootz
0 votes
<!DOCTYPE html>
<html>
<body>

<p>Enter a number - max 300:</p>

<input id="input-number-id" type="number" max="300">
<button onclick="checkFunction()">OK</button>

<p id="message-id"></p>

<script>
function checkFunction() 
{
    var msg = "";

    if (document.getElementById("input-number-id").validity.rangeOverflow) 
        msg = "Value too big";
    else 
        msg = "Input OK";
     
    document.getElementById("message-id").innerHTML = msg;
} 
</script>
</body>
</html>



answered Jun 29, 2015 by avibootz
edited Jun 29, 2015 by avibootz
0 votes
<!DOCTYPE html>
<html>
<body>

<p>Enter a number - min 20:</p>

<input id="input-number-id" type="number" min="20">
<button onclick="checkFunction()">OK</button>

<p id="message-id"></p>

<script>
function checkFunction() 
{
    var msg = "";
   
    if (document.getElementById("input-number-id").validity.rangeUnderflow) 
        msg = "Value too small";
    else 
        msg = "Input OK";
     
    document.getElementById("message-id").innerHTML = msg;
} 
</script>

</body>
</html>



answered Jun 29, 2015 by avibootz
...