Lets Smile
Lets Smile

Reputation: 11

Dont validate Input number HTML on Spring (appfuse)

I have an input as:

<form:input id="appetizerQuantity"  type="number" path="appetizerQuantity" max='999'  pattern="\d*" autocomplete="off" oncopy="return false;" onpaste="return false;" oncut="return false;"/>

I just want to import from -99 to 999

But I can enter into --00, -.01, 1e10 or -.-, - ..,. and I do not want to be like that.

I have validate to it as:

$('#appetizerQuantity').keypress(function (event) {
        console.log(event.which);
        console.log($('#appetizerQuantity').val().length);
         if($(this).val().length < 3) {
            return isNumber(event, this)
         } else{
             return false;
         }
     });

and

$("#appetizerQuantity").keydown(function (e) {
            // Allow: backspace, delete, tab, escape, enter and .
            if($(this).val().length < 4) {
                if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
                     // Allow: Ctrl+A
                    (e.keyCode == 65 && e.ctrlKey === true) ||
                    // Allow: Ctrl+C
                    (e.keyCode == 67 && e.ctrlKey === true) ||
                    // Allow: Ctrl+X
                    (e.keyCode == 88 && e.ctrlKey === true) ||
                    // Allow: home, end, left, right
                    (e.keyCode >= 35 && e.keyCode <= 39)) {
                     // let it happen, don't do anything
                    return;
                }
            }
        });

who can help me, please.

Note: I working with project use appfuse (spring+hybernate).

Thanks every body can help!

Upvotes: 1

Views: 55

Answers (2)

Lets Smile
Lets Smile

Reputation: 11

Thanks Matt Raible, i fixed it ! I change type="number" of input to "text" on IOS device and "tel" on Android. I used jquery.numeric.min.js libraries and add function:

$('#appetizerQuantity').numeric({decimal: false, negative: false },
function(){$(this).focus(); this.value = "";});

And it worked

Upvotes: 0

Matt Raible
Matt Raible

Reputation: 8644

You might be able to use the step attribute to limit the use of decimal places. See https://stackoverflow.com/a/19012837 for more information.

Upvotes: 0

Related Questions