1
So far I’m trying like this, but it didn’t work:
$('.peso').keyup(function () {
var v = this.value,
integer = v.split('.')[0];
v = v.replace(/\D/g, "");
v = v.replace(/^[0]+/, "");
if (v.length <= 3 || !integer) {
if (v.length === 1) v = '0.00' + v;
if (v.length === 2) v = '0.0' + v;
if (v.length === 3) v = '0.' + v;
} else { v = v.replace(/^(\d{1,})(\d{3})$/, "$1.$2");}
this.value = v;});
HTML:
<p><label>Capacacidade</label></p>
<div class="input-group has-success">
<input type="text" name="txtcapac" placeholder="Capacidade em Kg" class="peso form-control"/>
<div class="input-group-addon"><span>Kg</span></div>
You have already tried using jquery.Mask?
– Jeferson Assis
That one? Function mascara(t, Mask){ var i = t.value.length; var output = Mask.substring(1,0); var text = Mask.substring(i) if (text.substring(0,1) != output){ t.value += text.substring(0,1); } ; }
– Sarah
The plugin same, I will post an example as answer
– Jeferson Assis