3
I need to limit the value in R$ input field of a form. The form is like this:
<div class="container">
            <form>
                <div class="form-group">
                    <label for="dinheiro"><b>Desejo doar em R$: </label>
                    <input name="campo1" onkeypress="mascara(this,mreais)" size="7" min="10,00" max="1.064,00" /><br>                    
                    <small>Conforme resolução do TSE, as doações são limitadas a R$ 1.064,10 por dia e a 10% dos rendimentos brutos em 2017 para cada pré-candidato. </small><br>
                    <button type="submit" class="btn-doar-form">Doar com Pagseguro</button>           
                   <!-- <button type="submit" class="btn-doar-form">Doar com PayPal</button> -->
                </div>
            </form>
        </div>
And I made a script to assign R$ in the field like this:
<script type="text/javascript">
            function mascara(o, f) {
                v_obj = o
                v_fun = f
                setTimeout("execmascara()", 1)
            }
            function execmascara() {
                v_obj.value = v_fun(v_obj.value)
            }
            function mreais(v) {
                v = v.replace(/\D/g, "") //Remove tudo o que não é dígito
                v = v.replace(/(\d{2})$/, ",$1") //Coloca a virgula
                v = v.replace(/(\d+)(\d{3},\d{2})$/g, "$1.$2") //Coloca o primeiro ponto
                return v
            }
        </script>
How can I limit the maximum amount to R $ 1.064,00?
Max, if you put only "1064" does not work?
– Diego
No. Ai allows 1064 characters...
– Ramos
I tested it here and it worked, in 1065 he complained: "Please enter a value Less than or Equal to 1064."
– Diego