JavaScript mask error

3

I'm having trouble with the javascript mask for the phone field, I'm developing mobile and I'm using the codes below.

input code:

<input type="text" name="telefone" id="telefone" maxlength="15"/>

javascript code

$('#telefone').mask('(00) 0000-00009');
$('#telefone').blur(function(event) {
   if($(this).val().length == 15){ // Celular com 9 dígitos + 2 dígitos DDD e 4 da máscara
      $('#telefone').mask('(00) 00000-0009');
   } else {
      $('#telefone').mask('(00) 0000-00009');
   }
});

Console error:

Uncaught TypeError: undefined is not a function //Erro na linha do .maks(...)

What can it be? And how do you coordinate, does anyone have a better idea?

I need it to check if there is any letter and itself a mask.

Thank you in advance.

    
asked by anonymous 02.12.2015 / 03:52

2 answers

0

You must be forgetting to add the library call

<script type="text/javascript" src="js/jquery.mask.min.js"/></script>

Then just do something like this

<label for="txttelefone">Telefone</label>

<script type="text/javascript">$("#txttelefone").mask("(00) 0000-00009");</script>
    
02.12.2015 / 04:13
0

Make sure you've placed the jQuery plugin and Masked Input in that order, then start the plugin

(function($) {
    $(document).ready(function() {
        $('#telefone').mask('(00) 0000-00009'); 
    });
}).(jQuery);

See this page , example 4.

    
02.12.2015 / 04:49