Help with the validation of a name input mask in JS

1

I have an input which I am validating that I only enter letters, although it works, I also restrict the "spacebar" key. I am quite new in the use of this tool, I do not know how to add that key to the query in case the user decides to place two or more names.

$("#nombre").mask('SSSSSSSSSSS');
    
asked by FJAL 18.06.2018 в 14:59
source

1 answer

0

According to the official documentation , you can define the masks as you want, passing the options as a second parameter:

$('#texto').mask('AAAAAAAA',{
  translation: {
    A: {pattern: /[a-zA-ZñÑáéíóúü ]/} //todas las letras inglesas más la ñ y vocales acentuadas 
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.min.js"></script>
<input id="texto" type="text">
    
answered by 18.06.2018 / 16:50
source