Remove javascript mask

0

I have a field to insert telephone with option for international ddi, I would like to check if the first 2 digits are not 55 I want to remove the mask, but it is not working.

$("#tell_internacional").click(function(){
  var cell = $("#tell_internacional");
  if (cell.substring(2) != '55'){
    $("#tell_internacional").unmask();
    }
})
    
asked by anonymous 21.06.2017 / 16:11

1 answer

0

Follow the script to remove the mask after entering the phone in the field when the first two digits do not equal 55:

jQuery(function($){	
   $("#tell_internacional").mask("99(99)9999-9999");
});
jQuery(function($){	
  $("#tell_internacional").change(function (){
    var cell = $(this).val();
    if (cell.substring(0, 2) != '55'){
       $("#tell_internacional").unmask("99(99)9999-9999");
    }
  });
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scripttype="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.js"></script>Telefone<inputtype="text" id="tell_internacional">
    
21.06.2017 / 17:31