Click here to Skip to main content
16,012,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a number of inputs which are purely integers namely 0 to 54.
My code for input is thus
<td> <input id="P1HC" name="P1HC" type="number" min="0" max="54" size= "1"  pattern="^[1-9]$"  value="<?php echo $_SESSION["HC1"]; ?>"> </td>


However, I can still type 'e' into the input. It will not accept any other letter or characters other than 0 to 9 or e.
Also I can type in numbers greater than 54 why?

Any ideas?
Plan to validate in PHP server side but wanted to check at the user side first.

What I have tried:

Also tried adding
onchange = "check(this)"

with javascript of
function check(that) {
        var StringInput = that.value;
    if (!/^[1-9]*$/g.test(StringInput)) {
        alert("You have entered invalid characters");
        that.value = "";
        that.focus();
        return false;
    }
    }

Still did not work.
Posted
Updated 30-Nov-18 9:16am
Comments
Dave the Golfer 30-Nov-18 14:59pm    
Noticed that the validation is undertaken when the form is submitted.
But can it be done when the data is entered?

1 solution

Just realised e is for exponential.#

Question is a no no. needs deleting if i only knew how
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900