0

function retiraAcento(obj)

Posted by Fabio's Blog on 21:39
Esta função em Javascript serve para retirar o acento ao digitar no textbox, assim fica mais limpo na base de dados as informações.

Segue abaixo:

function retiraAcento(obj)
 {
    var palavra = event.keyCode
   
    var caracteresInvalidos = [192, 193, 194, 195, 196, 197, 224, 225, 226, 227, 228, 229, 199, 231, 200, 201, 202, 203, 232, 233, 234, 235, 204, 205, 206, 207, 236, 237, 238, 239, 210, 211, 212, 213, 214, 242, 243, 244, 245, 246, 217, 218, 219, 220, 249, 250, 251, 252 ];

    var caracteresValidos   = [65,  65 , 65 , 65 , 65 , 65 , 97 , 97 , 97 , 97 , 97 , 97 , 67 , 99 , 69 , 69 , 69 , 69 , 101, 101, 101, 101, 73 , 73 , 73 , 73 , 105, 105, 105, 105, 79 , 79 , 79 , 79 , 79 , 111, 111, 111, 111, 111, 85 , 85 , 85 , 85 , 117, 117, 117, 117 ];

    var acento              = [168, 39 , 94 , 96 , 126, 180 ];
   
   
    // Verificando Acentos
    for(a=0; a < acento.length; a++)
    {
        if(acento[a] == palavra)
        {
            window.event.keyCode = 0;
            return;
        }
    }
   
    // Verificando os caracteres inválidos, se existir, trocar pelo caracter válido
    for(a=0; a < caracteresInvalidos.length; a++)
    {
        if(caracteresInvalidos[a] == palavra)
        {
            window.event.keyCode = 0;
            nova = caracteresValidos[a];
            obj.value = obj.value + String.fromCharCode(nova);
            obj.value = obj.value.toUpperCase();
            return;
        }
    }
    window.event.keyCode = 0;
    obj.value = obj.value + String.fromCharCode(palavra);
    obj.value = obj.value.toUpperCase();
   
 }

// Deve ser incluido atributo no code behind como mostra abaixo

this.tbx_Nome.Attributes.Add("onKeyPress", "javascript:retiraAcento(this);");


 Espero que sirva para alguma coisa

Um abraço

Copyright © 2009 Fabio's Blog All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive. Distribuído por Templates