How do I make Jquery Mask not accept numbers?

Asked

Viewed 1,242 times

1

I am receiving a data that would be the first three digits alphabetic characters and the other 4 numeric (A vehicle plate).

I saw on a site that to receive only letters in Jquey Mask, just use the "A"

Example:

$('.placa').mask('AAA-0000');

But using this example, the user can enter numbers before the hyphen without any problems...

Does anyone know how I can fix this?

1 answer

1

I will try to make this answer very complete since this question is very interesting and I was looking for it myself a long time ago and I believe that other people will also look into it.

In this example was used only

  • HTML
  • jQuery

Very simple using the plugin jQuery Masked Input, in the example there are 3 fields, one text only, another text and number and finally only number.

$(function() {
  $('#apenasnumero').mask('(99) 9999-9999');

  $('#apenasletra').mask('aaaaaaaa');

  $('#letrasnumeros').mask('********');
});
<head>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js">
  </script>
  <!-- link para o plugin de mascara -->
  <script type="text/javascript" src="http://tutsmais.com.br/blog/arquivos/mascara/jquery.maskedinput-1.2.2.min.js">
  </script>
</head>
Apenas Letras:
<input type="text" id="apenasletra" />
<br>Letras e Números
<input type="text" id="letrasnumeros" />
<br>Apenas Número:
<input type="text" id="apenasnumero" />
<br>

If you have any questions, just comment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.