How to do regular expression to accept words and then 2 numbers with jQuery, without special characters?

2

Hello everyone. Next, I am doing a regular expression to accept the following: Word 02. Word and numbers, not just numbers. I'm using this code:

$(".inputNomeTurma").keyup(function() {
    var valor = $(this).val().replace(/(([a-zA-Z]*\d{3,})|[!"#$%&'()*+ºª,-./:;<=>?@[\]_{|}])/,'');
    $(this).val(valor);
});

Okay, if I click on a * character for example, it does the replace. But if I press and hold the *, the field accepts the special character.

    
asked by anonymous 26.01.2016 / 15:43

1 answer

1

I understand this should resolve

  

/ [^ \ w] / g

[^\w] corresponde a um caractere único não está presente na lista abaixo
   \w corresponde a qualquer caractere de palavra [a-zA-Z0-9_]
modificador g: global

or maybe this fits your problem better:

$(".inputNomeTurma").keyup(function() {
    var valor = $(this).val();
    var reg   = /([a-zA-Z])+([0-9]{2})/g;
    var encontrados = reg.exec(valor);
    console.log(encontrados);
    $(this).val(encontrados[0]);
});
    
26.01.2016 / 17:36