Allow only trace number (hyphen), slash and dot in inpult [duplicate]

0

I'm trying to make a CPF & CNPJ with mask, but I want to allow in the field only number, dash (hyphen), bar & point;

and I want to for mask it works so when I had 14 digit (CPF) it make the mask of the same and 18 (CNPJ).

OBS: Excuse me, I'm sorry in Portuguese.

function mask(InputMask, DocMask){
  var m = DocMask.value.length;
  var MSay = InputMask.substring(0,1);
  var MText = InputMask.substring(m)
  if (MText.substring(0,1) != MSay){
    DocMask.value += MText.substring(0,1);
  }
}
$("input[name='doc']").on('blur', function(){
  var doc = $(this).val();
  $.get('./functions/filter.php?doc=' + doc,function(data){
    $('#doc').html(data);
  });
});
jQuery('.doc').keyup(function () { 
    this.value = this.value.replace(/[^0-9.-]/g,'');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><inputclass="input100 doc" type="text" name="doc" autocomplete="off" required="required" placeholder="CPF/CNPJ" minlength="14" maxlength="18" OnKeyPress="mask('###.###.###-##', this)">
    
asked by anonymous 12.08.2018 / 06:01

0 answers