[5307] | 1 | |
---|
| 2 | /* ************************************************************************************************ |
---|
| 3 | Função: formatar(campo,mascara) |
---|
| 4 | Autor: Alex Nunes Wzorek |
---|
| 5 | Data: 26/08/2008 |
---|
| 6 | Descrição: Função utilizada para formatar máscaras genéricas em campos text |
---|
| 7 | @ - numeros |
---|
| 8 | # - demais caracteres |
---|
| 9 | OnKeyUp="formatar(this,'###-@@/@@@@')" |
---|
| 10 | **************************************************************************************************/ |
---|
| 11 | |
---|
| 12 | function formatar(campo, mask){ |
---|
| 13 | if(navigator.appName == 'Konqueror') { |
---|
| 14 | if(window.event && window.event.toString() == "[object KeyboardEvent]"){ |
---|
| 15 | return true; |
---|
| 16 | } |
---|
| 17 | } |
---|
| 18 | //verifica se mascara é para somente números |
---|
| 19 | if(mask == '@'){ |
---|
| 20 | campo.value = campo.value.replace(/\D/g,""); |
---|
| 21 | return; |
---|
| 22 | /*if(!parseInt(campo.value)) |
---|
| 23 | campo.value = ''; |
---|
| 24 | else |
---|
| 25 | campo.value = parseInt(campo.value); |
---|
| 26 | return '';*/ |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | if(campo.value.length > mask.length){ |
---|
| 30 | campo.value = campo.value.substring(0,mask.length); |
---|
| 31 | } |
---|
| 32 | else { |
---|
| 33 | var i = campo.value.length -1; |
---|
| 34 | var texto = mask.substring(i); |
---|
| 35 | if(texto.substring(0,1) != '#'){ |
---|
| 36 | for(j=i;j<=mask.length;j++) { |
---|
| 37 | if(mask.substring(j,j+1) == '@'){ |
---|
| 38 | var valida = campo.value.substring(j,j+1); |
---|
| 39 | if((valida != 0 && valida != 1 && valida != 2 && valida != 3 && valida != 4 && valida != 5 && valida != 6 && valida != 7 && valida != 8 && valida != 9) || valida==" ") |
---|
| 40 | campo.value = campo.value.substr(0,i); |
---|
| 41 | break; |
---|
| 42 | } |
---|
| 43 | else { |
---|
| 44 | if(mask.substring(j,j+1) == '#' || mask.substring(j,j+1) == campo.value.substring(j)) |
---|
| 45 | break; |
---|
| 46 | var saida = '#'; |
---|
| 47 | if (mask.substring(j,j+1) != saida) |
---|
| 48 | { |
---|
| 49 | campo.value = campo.value.substring(0,j) + mask.substring(j,j+1) + campo.value.substring(j); |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | /* ************************************************************************************************ |
---|
| 59 | Função: revalidar(campo,mascara,validacao) |
---|
| 60 | Autor: Alex Nunes Wzorek |
---|
| 61 | Data: 26/08/2008 |
---|
| 62 | Descrição: Função utilizada para atribuir a máscara e validar campos específicos. |
---|
| 63 | Chama a função formatar(), para evitar erros no caso do usuário colar um valor (ctrl+v) |
---|
| 64 | para o campo text. |
---|
| 65 | OnBlur="formatar(this,'@@@.@@@.@@@-@@','cpf')" |
---|
| 66 | **************************************************************************************************/ |
---|
| 67 | |
---|
| 68 | function revalidar(campo,mask,validacao){ |
---|
| 69 | campo.style.background = "#FFFFFF"; |
---|
| 70 | if(mask != ''){ |
---|
| 71 | var aux = campo.value; |
---|
| 72 | campo.value = ''; |
---|
| 73 | if(mask == '@'){ |
---|
| 74 | // Alterado por Ricardo - 19/09/2008 |
---|
| 75 | //if(parseInt(aux)) |
---|
| 76 | // campo.value = parseInt(aux); |
---|
| 77 | campo.value = aux.replace(/\D/g,""); |
---|
| 78 | } |
---|
| 79 | else{ |
---|
| 80 | for(i=0;i<aux.length;i++){ |
---|
| 81 | campo.value += aux.substr(i,1); |
---|
| 82 | formatar(campo,mask); |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | switch (validacao) { |
---|
| 87 | case 'cnpj': |
---|
| 88 | var valor = campo.value; |
---|
| 89 | |
---|
| 90 | valor = valor.replace (".","").replace (".","").replace ("-","").replace ("/",""); |
---|
| 91 | |
---|
| 92 | var a = []; |
---|
| 93 | var b = new Number; |
---|
| 94 | var c = [6,5,4,3,2,9,8,7,6,5,4,3,2]; |
---|
| 95 | for (i=0; i<12; i++){ |
---|
| 96 | a[i] = valor.charAt(i); |
---|
| 97 | b += a[i] * c[i+1]; |
---|
| 98 | } |
---|
| 99 | if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x } |
---|
| 100 | b = 0; |
---|
| 101 | for (y=0; y<13; y++) { |
---|
| 102 | b += (a[y] * c[y]); |
---|
| 103 | } |
---|
| 104 | if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; } |
---|
| 105 | if ((valor.charAt(12) != a[12]) || (valor.charAt(13) != a[13])){ |
---|
| 106 | campo.style.background = "#FFFFC0"; |
---|
| 107 | campo.value = ''; |
---|
| 108 | return false; |
---|
| 109 | } |
---|
| 110 | break; |
---|
| 111 | |
---|
| 112 | case 'email': |
---|
| 113 | |
---|
| 114 | if (trim(campo.value) != ""){ |
---|
| 115 | var vemail =/^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/; |
---|
| 116 | if(!vemail.test(campo.value)){ |
---|
| 117 | campo.style.background = "#FFFFC0"; |
---|
| 118 | campo.value = ''; |
---|
| 119 | return false; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | break; |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | case 'cpf': |
---|
| 126 | |
---|
| 127 | var valor = campo.value.replace('.','').replace('.','').replace('-',''); |
---|
| 128 | |
---|
| 129 | if(valor.length != 11 || valor == "00000000000" || valor == "11111111111" || |
---|
| 130 | valor == "22222222222" || valor == "33333333333" || valor == "44444444444" || |
---|
| 131 | valor == "55555555555" || valor == "66666666666" || valor == "77777777777" || |
---|
| 132 | valor == "88888888888" || valor == "99999999999"){ |
---|
| 133 | campo.style.background = "#FFFFC0"; |
---|
| 134 | campo.value = ''; |
---|
| 135 | return false; |
---|
| 136 | break; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | soma = 0; |
---|
| 140 | for(i = 0; i < 9; i++) |
---|
| 141 | soma += parseInt(valor.charAt(i)) * (10 - i); |
---|
| 142 | resto = 11 - (soma % 11); |
---|
| 143 | if(resto == 10 || resto == 11) |
---|
| 144 | resto = 0; |
---|
| 145 | if(resto != parseInt(valor.charAt(9))){ |
---|
| 146 | campo.style.background = "#FFFFC0"; |
---|
| 147 | campo.value = ''; |
---|
| 148 | return false; |
---|
| 149 | } |
---|
| 150 | soma = 0; |
---|
| 151 | for(i = 0; i < 10; i ++) |
---|
| 152 | soma += parseInt(valor.charAt(i)) * (11 - i); |
---|
| 153 | resto = 11 - (soma % 11); |
---|
| 154 | if(resto == 10 || resto == 11) |
---|
| 155 | resto = 0; |
---|
| 156 | if(resto != parseInt(valor.charAt(10))){ |
---|
| 157 | campo.style.background = "#FFFFC0"; |
---|
| 158 | campo.value = ''; |
---|
| 159 | return false; |
---|
| 160 | } |
---|
| 161 | break |
---|
| 162 | |
---|
| 163 | case 'data': |
---|
| 164 | |
---|
| 165 | var tam = campo.length; |
---|
| 166 | var dia = campo.value.substr(0,2); |
---|
| 167 | var mes = campo.value.substr (3,2); |
---|
| 168 | var ano = campo.value.substr (6,4); |
---|
| 169 | var array_campo = campo.value.split('/'); |
---|
| 170 | |
---|
| 171 | if (array_campo.length < 3) { |
---|
| 172 | campo.value = ''; |
---|
| 173 | campo.style.background = "#FFFFC0"; |
---|
| 174 | return false; |
---|
| 175 | } else { |
---|
| 176 | if (array_campo[2].length < 4) { |
---|
| 177 | campo.value = ''; |
---|
| 178 | campo.style.background = "#FFFFC0"; |
---|
| 179 | return false; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | if (dia > 31 || dia == 0) { |
---|
| 183 | campo.value = ''; |
---|
| 184 | campo.style.background = "#FFFFC0"; |
---|
| 185 | return false; |
---|
| 186 | } |
---|
| 187 | if (mes < 1 || mes > 12) { |
---|
| 188 | campo.value = ''; |
---|
| 189 | campo.style.background = "#FFFFC0"; |
---|
| 190 | return false; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | var date = new Date(); |
---|
| 194 | if(ano < (date.getFullYear() - 15) || ano > (date.getFullYear() +15)){ |
---|
| 195 | campo.style.background = "#FFFFC0"; |
---|
| 196 | return false; |
---|
| 197 | } |
---|
| 198 | if(mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12){ |
---|
| 199 | if (dia > 31){ |
---|
| 200 | campo.style.background = "#FFFFC0"; |
---|
| 201 | campo.value = ''; |
---|
| 202 | return false; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | if(mes == 4 || mes == 6 || mes == 9 || mes == 11){ |
---|
| 206 | if (dia > 30){ |
---|
| 207 | campo.style.background = "#FFFFC0"; |
---|
| 208 | campo.value = ''; |
---|
| 209 | return false; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | //verifica bisexto |
---|
| 213 | if(mes == 2 && ( dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))){ |
---|
| 214 | campo.style.background = "#FFFFC0"; |
---|
| 215 | campo.value = ''; |
---|
| 216 | return false; |
---|
| 217 | } |
---|
| 218 | if(mes > 12 || mes < 1){ |
---|
| 219 | campo.style.background = "#FFFFC0"; |
---|
| 220 | campo.value = ''; |
---|
| 221 | return false; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | break; |
---|
| 225 | |
---|
| 226 | case 'hora': |
---|
| 227 | |
---|
| 228 | var tam = campo.length; |
---|
| 229 | var hora = campo.value.substr(0,2); |
---|
| 230 | var min = campo.value.substr (3,2); |
---|
| 231 | var array_campo = campo.value.split(':'); |
---|
| 232 | |
---|
| 233 | if (array_campo.length < 2) { |
---|
| 234 | campo.value = ''; |
---|
| 235 | campo.style.background = "#FFFFC0"; |
---|
| 236 | return false; |
---|
| 237 | } else { |
---|
| 238 | if (array_campo[0].length < 2 || array_campo[1].length < 2) { |
---|
| 239 | campo.value = ''; |
---|
| 240 | campo.style.background = "#FFFFC0"; |
---|
| 241 | return false; |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | if (hora > 23 || hora < 0 ) { |
---|
| 245 | campo.value = ''; |
---|
| 246 | campo.style.background = "#FFFFC0"; |
---|
| 247 | return false; |
---|
| 248 | } |
---|
| 249 | if (min < 0 || min > 59) { |
---|
| 250 | campo.value = ''; |
---|
| 251 | campo.style.background = "#FFFFC0"; |
---|
| 252 | return false; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | break; |
---|
| 256 | |
---|
| 257 | case 'tempo': |
---|
| 258 | |
---|
| 259 | var tam = campo.length; |
---|
| 260 | var hora = campo.value.substr(0,2); |
---|
| 261 | var min = campo.value.substr (3,2); |
---|
| 262 | var array_campo = campo.value.split(':'); |
---|
| 263 | |
---|
| 264 | if (array_campo.length < 2) { |
---|
| 265 | campo.value = ''; |
---|
| 266 | campo.style.background = "#FFFFC0"; |
---|
| 267 | return false; |
---|
| 268 | } else { |
---|
| 269 | if (array_campo[0].length < 2 || array_campo[1].length < 2) { |
---|
| 270 | campo.value = ''; |
---|
| 271 | campo.style.background = "#FFFFC0"; |
---|
| 272 | return false; |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | if (min < 0 || min > 59) { |
---|
| 276 | campo.value = ''; |
---|
| 277 | campo.style.background = "#FFFFC0"; |
---|
| 278 | return false; |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | break; |
---|
| 282 | |
---|
| 283 | case 'mesAno': |
---|
| 284 | |
---|
| 285 | var tam = campo.length; |
---|
| 286 | var mes = campo.value.substr (0,2); |
---|
| 287 | var ano = campo.value.substr (3,4); |
---|
| 288 | var array_campo = campo.value.split('/'); |
---|
| 289 | |
---|
| 290 | if (array_campo.length < 2) { |
---|
| 291 | campo.value = ''; |
---|
| 292 | campo.style.background = "#FFFFC0"; |
---|
| 293 | return false; |
---|
| 294 | } else { |
---|
| 295 | if (array_campo[1].length < 4) { |
---|
| 296 | campo.value = ''; |
---|
| 297 | campo.style.background = "#FFFFC0"; |
---|
| 298 | return false; |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | if (mes < 1 || mes > 12) { |
---|
| 302 | campo.value = ''; |
---|
| 303 | campo.style.background = "#FFFFC0"; |
---|
| 304 | return false; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | var date = new Date(); |
---|
| 308 | if(ano < (date.getFullYear() - 15) || ano > (date.getFullYear() +15)){ |
---|
| 309 | campo.style.background = "#FFFFC0"; |
---|
| 310 | return false; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | break; |
---|
| 314 | } |
---|
| 315 | campo.style.background = ""; |
---|
| 316 | return true; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | /* ************************************************************************************************ |
---|
| 320 | Função: moeda(campo,casas) |
---|
| 321 | Autor: Alex Nunes Wzorek |
---|
| 322 | Data: 26/08/2008 |
---|
| 323 | Descrição: Função utilizada para formatar valores monetários com separador de milhar (.) e decimal (,). |
---|
| 324 | O segundo parametro é o número de casas decimais desejado |
---|
| 325 | OnKeyUp="moeda(this,2)" |
---|
| 326 | **************************************************************************************************/ |
---|
| 327 | |
---|
| 328 | function moeda(campo,casas){ |
---|
| 329 | if(navigator.appName == 'Konqueror') { |
---|
| 330 | if(window.event.toString() == "[object KeyboardEvent]"){ |
---|
| 331 | return true; |
---|
| 332 | } |
---|
| 333 | } |
---|
| 334 | var valida = campo.value.substring(campo.value.length-1); |
---|
| 335 | if((valida != 0 && valida != 1 && valida != 2 && valida != 3 && valida != 4 && valida != 5 && valida != 6 && valida != 7 && valida != 8 && valida != 9) || valida == ' '){ |
---|
| 336 | campo.value = campo.value.substr(0,campo.value.length-1); |
---|
| 337 | } |
---|
| 338 | campo.value = campo.value.replace('.','').replace(',','.'); |
---|
| 339 | if(parseFloat(campo.value) < 1){ |
---|
| 340 | campo.value = parseFloat(campo.value.replace('0.','')); |
---|
| 341 | } |
---|
| 342 | var zeros = ''; |
---|
| 343 | if(campo.value.length <= casas){ |
---|
| 344 | for(i=0;i<casas-campo.value.length;i++){ |
---|
| 345 | zeros += '0'; |
---|
| 346 | } |
---|
| 347 | campo.value = '0,' + zeros + campo.value; |
---|
| 348 | } |
---|
| 349 | else{ |
---|
| 350 | if(campo.value.length > (casas+4)){ |
---|
| 351 | var decimal = campo.value.substr(campo.value.length-(casas)); |
---|
| 352 | var inteiro = campo.value.substr(0,campo.value.length-casas).replace(/\./g,''); |
---|
| 353 | var milhar = ''; |
---|
| 354 | for(i=0;i<inteiro.length;){ |
---|
| 355 | i+=3; |
---|
| 356 | if((inteiro.substr(inteiro.length-(i+1),4).length == 4) && ((inteiro.length-(i+1)) >= 0)){ |
---|
| 357 | milhar = inteiro.substr(inteiro.length-i,3) + '.' + milhar; |
---|
| 358 | } |
---|
| 359 | else{ |
---|
| 360 | milhar = inteiro.substr(0,(inteiro.length-(i+1))+4) + '.' + milhar; |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | if(milhar != '') |
---|
| 364 | campo.value = milhar.substr(0,milhar.length-1) + ',' +decimal; |
---|
| 365 | } |
---|
| 366 | else{ |
---|
| 367 | campo.value = campo.value.substr(0,campo.value.length -casas).replace('.','') + ',' + campo.value.substr(campo.value.length -casas); |
---|
| 368 | } |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | /* ************************************************************************************************ |
---|
| 373 | Função: revalidarMoeda(campo,casas) |
---|
| 374 | Autor: Alex Nunes Wzorek |
---|
| 375 | Data: 26/08/2008 |
---|
| 376 | Descrição: Função utilizada para formatar valores monetários com separador de milhar (.) e decimal (,). |
---|
| 377 | Chama a função moeda, para formatar valores que possam ter sido colados (ctrl+v) pelo usuario. |
---|
| 378 | OnBlur="moeda(this,2)" |
---|
| 379 | **************************************************************************************************/ |
---|
| 380 | |
---|
| 381 | function revalidarMoeda(campo,casas){ |
---|
| 382 | aux = campo.value; |
---|
| 383 | campo.value = ''; |
---|
| 384 | for(j=0;j<aux.length;j++){ |
---|
| 385 | campo.value += aux.substr(j,1); |
---|
| 386 | moeda(campo,casas); |
---|
| 387 | } |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | /* ************************************************************************************************ |
---|
| 391 | Função: milhar(campo) |
---|
| 392 | Autor: Ricardo Andre Pikussa |
---|
| 393 | Data: 26/08/2008 |
---|
| 394 | Descrição: Função utilizada para formatar valores numerico com separador de milhar (.). |
---|
| 395 | OnKeyUp="milhar(this);" |
---|
| 396 | **************************************************************************************************/ |
---|
| 397 | |
---|
| 398 | function milhar(campo){ |
---|
| 399 | if(navigator.appName == 'Konqueror') { |
---|
| 400 | if(window.event.toString() == "[object KeyboardEvent]"){ |
---|
| 401 | return true; |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | var valida = campo.value.substring(campo.value.length-1); |
---|
| 405 | if((valida != 0 && valida != 1 && valida != 2 && valida != 3 && valida != 4 && valida != 5 && valida != 6 && valida != 7 && valida != 8 && valida != 9) || valida == ' '){ |
---|
| 406 | campo.value = campo.value.substr(0,campo.value.length-1); |
---|
| 407 | } |
---|
| 408 | campo.value = campo.value.replace('.','').replace(',','.'); |
---|
| 409 | if(parseFloat(campo.value) < 1){ |
---|
| 410 | campo.value = parseFloat(campo.value.replace('0.','')); |
---|
| 411 | } |
---|
| 412 | if(campo.value.length >= 3){ |
---|
| 413 | var decimal = campo.value.substr(campo.value.length); |
---|
| 414 | var inteiro = campo.value.substr(0,campo.value.length).replace(/\./g,''); |
---|
| 415 | var milhar = ''; |
---|
| 416 | for(i=0;i<inteiro.length;){ |
---|
| 417 | i+=3; |
---|
| 418 | if((inteiro.substr(inteiro.length-(i+1),4).length == 4) && ((inteiro.length-(i+1)) >= 0)){ |
---|
| 419 | milhar = inteiro.substr(inteiro.length-i,3) + '.' + milhar; |
---|
| 420 | } else { |
---|
| 421 | milhar = inteiro.substr(0,(inteiro.length-(i+1))+4) + '.' + milhar; |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | if(milhar != '') |
---|
| 425 | campo.value = milhar.substr(0,milhar.length-1) + decimal; |
---|
| 426 | } else { |
---|
| 427 | campo.value = campo.value.substr(0,campo.value.length).replace('.','') + campo.value.substr(campo.value.length); |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | /** |
---|
| 432 | * Função: revalidarMilhar(campo) |
---|
| 433 | * Autor: Ricardo Andre Pikussa |
---|
| 434 | * Data: 26/08/2008 |
---|
| 435 | * Descrição: Função utilizada para formatar valores numerricos com separador de milhar (.). |
---|
| 436 | Chama a função milhar, para formatar valores que possam ter sido colados (ctrl+v) pelo usuario. |
---|
| 437 | * Chamada: OnBlur="revalidarMilhar(this);" |
---|
| 438 | */ |
---|
| 439 | function revalidarMilhar(campo){ |
---|
| 440 | aux = campo.value; |
---|
| 441 | campo.value = ''; |
---|
| 442 | for(j=0;j<aux.length;j++){ |
---|
| 443 | campo.value += aux.substr(j,1); |
---|
| 444 | milhar(campo); |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | /** |
---|
| 449 | * Função: retiraCaracteres(campo,upper) |
---|
| 450 | * Autor: Ricardo Andre Pikussa |
---|
| 451 | * Data: 12/12/2008 |
---|
| 452 | * Descrição: Função utilizada para retiraar caracteres indesejados em campos text |
---|
| 453 | Se preciso ela tambem passa os caracteres para caixa alta |
---|
| 454 | * Chamada: onBlur="retiraCaracteres(this);" |
---|
| 455 | */ |
---|
| 456 | function retiraCaracteres(campo, upper) |
---|
| 457 | { |
---|
| 458 | campo.value = campo.value.replace(/[\'°ºª]/g,""); |
---|
| 459 | if (upper == 'true') { |
---|
| 460 | campo.value = campo.value.toUpperCase(); |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | function somenteNumero(campo){ |
---|
| 465 | |
---|
| 466 | var digits = "0123456789."; |
---|
| 467 | var campo_temp |
---|
| 468 | |
---|
| 469 | for (var i=0;i<campo.value.length;i++){ |
---|
| 470 | |
---|
| 471 | campo_temp=campo.value.substring(i,i+1) |
---|
| 472 | |
---|
| 473 | if (digits.indexOf(campo_temp)==-1){ |
---|
| 474 | |
---|
| 475 | campo.value = campo.value.substring(0,i); |
---|
| 476 | break; |
---|
| 477 | } |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | function revalidaSomenteNumero(campo,casas){ |
---|
| 482 | |
---|
| 483 | var digits = "0123456789."; |
---|
| 484 | var campo_temp; |
---|
| 485 | |
---|
| 486 | for (var i=0;i<campo.value.length;i++){ |
---|
| 487 | |
---|
| 488 | campo_temp = campo.value.substring(i,i+1) |
---|
| 489 | |
---|
| 490 | if (digits.indexOf(campo_temp)==-1){ |
---|
| 491 | campo.value = campo.value.substring(0,i); |
---|
| 492 | break; |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | valor = campo.value; |
---|
| 497 | |
---|
| 498 | if(valor.length > 0){ |
---|
| 499 | |
---|
| 500 | valor = parseFloat(valor); |
---|
| 501 | campo.value = valor.toFixed(casas); |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|