Replicate phone mask in multiple fields

0

I have a form where the user who is filling in can include multiple cell numbers, but my mask function only works on the first field.

var telMask = ['(99) 9999-99999', '(99) 99999-9999'];
var tel_1 = document.querySelector('#celular');
VMasker(tel_1).maskPattern(telMask[0]);
tel_1.addEventListener('input', inputHandler.bind(undefined, telMask, 14), false);
    
asked by anonymous 05.04.2018 / 16:06

1 answer

2

Try to put the mascara after the code loads, via "Class" of the HTML. Here's an example below:

<head>
     
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     
    <title>Criando máscaras com jquery</title>
     
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script><scripttype="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.min.js"></script></head><scripttype="text/javascript">
     
      $(document).ready(function(){ 
        $("input.fone").mask("(99) 9999-99999");
      });
     
    </script>
    
    <body>
     
      <h1>Usando máscaras com jquery</h1>
     
      <label for="fone">Fone:</label><br>
     
      <input type="text" class="fone" id="fone" name="fone" /><br><br>
    
    </body>
     
    </html>
    
05.04.2018 / 19:37