Limit number in input box

Asked

Viewed 142 times

0

I wanted to know how I limit the maximum number before and after the point.

Like, make it 3 numbers before the dot and 2 numbers after. How do I do this?

Code:

<script> 
function soma() 
{
form.campo4.value = parseInt(form.campo1.value*1) * parseInt(form.campo2.value*1) 
}
</script>
<script type="text/javascript">
$(function(){
 $("#demo4").maskMoney({symbol:'R$ ', 
showSymbol:true, thousands:'', decimal:'.', symbolStay: false});
 })

 $(function() {
   $(document).on('click', 'input[value][id=demo4]', function() {
     this.select();
   });

 });
 $("#demo4").bind('input propertychange', function(){
    if($(this).val() > 4){
         $(this).val() = 4;
    }else if($(this).val() < 1){
         $(this).val() = 1;
    }
});
</script>
  • See the answer. If you enable "R$", you need to limit the field to 9 characters.

  • Dvdsamm as I do to put so in the input that I will put the value I want when typing the value from 1 to 99 ]

1 answer

2


Boot maxlength="9" in the input you want to do this.

With this, the field will not receive more than 5 characters typed (already with the decimal point and the symbol "R$ ").

Example: R$ 200.00

  • Dvdsamm as I do to put so in the input I go by the value I want when typing the value from 1 to 99 it multiply by [ 20 ] and when it is greater than 100 it multiply by [ 23 ]

  • @Andréjunior When do you want this to happen? When to move out of the field (Blur)?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.