javascript - How to prevent user from entering decimals? -


I have an order page on my site. Some order items can have decimal quantities, nothing can do

What is the best way to stop the user from entering the decimal quantity? (Except for a warning box and to set the area to zero)?

Intercept key events for fields, find illegal characters on the input, by entering them in the field Stop and add a temporary message near the area (inserted in the page) which tells which characters or values ​​are allowed. There is a bad way to respond between pop-up alert typing.

Then, please validate before submitting as there are other ways to get data in fields (drag / drop, copy / paste, etc.) that you can not catch everything is.

With the temporary messages that appear when typed invalid keys, this is just a round and a jQuery example of decimal decimals:

Working JSField: < Pre> $ ("integer"). Keypress (function (e) {if (e.which & lt; 48 || e.which> 57) {showAdvice (this, "integer value only"); return (wrong);}}); $ (". Decimal") Keypress (function (E) {46} is a duration (E. Joe !! = 46 & amp; amp; amp; amp; hht> 48; ehih;; 57)) {ShowAdvice ( This, "decimal numbers only"); Return (false);} if (ehii IE 46 & amp; amp; amp; this.value.indexOf (".") = -1) {showAdvice (this, "Decimal Only one period allowed in the number "); Return (false); // Only a decimal allowed}}); Function Show Device (Oz, msg) {$ ("#One Device") Stop (true, false) .remove (); $ ('& Lt; span id = "single device" category = "advisory" & gt;' + msg + ';) InsertAfter (obj); $ ("# SingleAdvice") Delay (4000) .fadeOut (1500) }

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -