Replace text with asterisk jQuery

2

I have the following field:

<input type="number" name="teste_senha">

I need that, when typing some content, this content is replaced by *****, without losing its original content, and can be stored in a hidden field.

How do I get to this result?

    
asked by anonymous 12.12.2017 / 21:51

1 answer

5

As they commented, it does not make much sense what you want, is to have more work for nothing. HTML already has its own attribute for hiding passwords with asterisks: type="password" .

What you can do, if you just want numbers in input , is to do a validation via JavaScript. Using regex would be an option:

function validar(){
   if( /^[0-9]*$/.test($("#campo").val()) && $("#campo").val()){
      alert("Ok!");
   }else{
      alert("Erro! Só são permitidos números");
   }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="campo" type="password" name="teste_senha">
<br />
<input type="button" value="Verificar" onclick="validar()">
    
12.12.2017 / 23:40