Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
How to restrict apart from alphabets and numbers any other keys (function keys, shortcut keys etc.) press action on datatable search input?

Jquery:

Is there please an option to start the search only alphabet and number keys have been typed in?

Datatable globally searching should initiate at least with 3 characters

$(document).on('draw.dt','.dataTable', function() {            
    $(".dataTables_filter input").off().on("input keyup", function(e) { 
        // if value length is greater than 3 or user press enter (keycode = 13) on search we will search on datatable
        if(this.value.length >= 3 || e.keyCode == 13 || this.value == "") {
            var dataTable = $('.table').DataTable();
            dataTable.search(this.value).draw();
        }
    }); 
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use regular expressions with preg_replace to remove letters other than alpha-numeric on every keyup and then check the length of a string.

Hope you get the desired result.

about 4 years ago · Juan Pablo Isaza Relatório

0

Solution:

Check this solution. I hope, it will work.

$(document).on('draw.dt','.dataTable', function() {

$(".dataTables_filter input").off().on("input keyup", function(e) { 
    // if value length is greater than 3 or user press enter (keycode = 13) on search we will search on datatable
    if(this.value.length >= 3 || e.keyCode == 13 || this.value == "") {
        var checkBackspaceEnter =  e.keyCode == 8 || e.keyCode == 13; // if user remove character from search we will search
        var checkAlphabet = (e.keyCode >= 58 && e.keyCode <= 90);   // check on alphabets
        var checkNum = (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105); // check on number values
        var ctrlCombine = (e.keyCode == 17 || ((e.keyCode == 65 || e.keyCode == 67 ) && e.ctrlKey)); // donot search when user hit Ctrl+A or Ctrl+C 
        checkAlphabet = ((ctrlCombine == false) ? checkAlphabet : false);   

        if ( checkAlphabet || checkNum || checkBackspaceEnter) {
            var dataTable = $('.table').DataTable();
            dataTable.search(this.value).draw();
        }
    }
}); 

});

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda