Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá,
Tenho uma função javascript para mascarar numeros, essa função é reconhecida no IE, mas não Firefox, O QUE PRECISA PARA QUE O FF TAMBÉM TECONHEÇA ESSA FUNÇÃO? se alguém puder verificar o código e me auxiliar, agradeço.
A FUNÇÃO JAVASCRIPT:
function FormataValor(campo,tammax) {
var campo = document.getElementById(campo.id);
var vr = campo.value;
var exp;
var tecla = (window.event)?event.keyCode:evento.which;//'windos':'fox';
if ( ( ( ( tecla >= 48 ) && ( tecla <= 57 ) ) ||
( ( tecla >= 96 ) && ( tecla <= 105 ) ) ) &&
( campo.value.length <= tammax ) ) {
exp = /[^0-9]/;
while ( exp.test(vr) )
vr = vr.replace(exp, "");
tam = vr.length;
if ( tam == 0 )
campo.value = "0,0" + campo.value;
else {
if ( parseFloat(vr) != 0 ) {
campo.value = parseFloat(vr) / 100;
}
campo.value = campo.value.replace( ".", "," );
if ( campo.value.search(/\,/) <= 0 )
campo.value = campo.value + ",00";
else if ( /\,\d$/.test(campo.value) )
campo.value = campo.value + "0";
if ( tam > 5 ) {
var str = vr.substr( 0, (tam % 3) + 1 ) + ".";
for(i=1; i<= parseInt((tam - 6)/3); i++)
str = str + vr.substr( (tam - 2) % 3 + 3*(i-1), 3) + ".";
campo.value = str + campo.value.substr( campo.value.length - 6, 6 ) ;
}
}
}
else {
exp = /[^0-9\.\,]/;
i = 0;
while ( (exp.test(vr)) && (i++<10) )
campo.value = campo.value.replace(exp, "");
}
}
function tamanho(numero) {
var obj=document.getElementById(numero.id);
var i = parseFloat(obj.value);
if (i>10){
obj.focus();
obj.select();
alert("Digite valores entre 0-10");
obj.value="";
obj.focus();
obj.select();
}
}
É CHAMADA NO ASPX
<asp:TextBox id="TextBox1" onblur="tamanho(this)" onkeyup="FormataValor(this, 5)" runat="server" font-names="Verdana" font-size="12px" width="50px"></asp:TextBox>
Carregando comentários...