Error masking JavaScript

Question:

Well I'm having problems 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');
   }
});

Erro no console:

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

What can it be ? And how to fix it, does anyone have any better ideas?

I need it to check if there are any letters and itself a mask.

Thanks in advance.

Answer:

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>
Scroll to Top