You can do it in several ways, I’ll show you the simplest one. There is a library of your own that you can "Import" through link .
<script type="text/javascript" src="js/jquery.mask.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
add this script below in your HTML as well
<script type="text/javascript">
$(document).ready(function(){
$('#cpf').mask('00000-000');
$('#cnpj').mask('00.000.000/0000-00');
$('#telefone').mask('0000-0000');
});
</script>
And in your input just put the ID referring to what you entered in Javascript. But, you can also create a class and reference by $('.cpf').mask('00000-000);
however, you will have to change your input and instead of id put class='cpf'
<input type='text' name='cpf' id='cpf'>
<input type='text' name='cnpj' id='cnpj'>
<input type='text' name='telefone' id='telefone'>
Remembering that if you want to send directly to the database, in its variables you will have to do a process to eliminate the points, I will leave below a simple example of how it should be done.
$chars = array(".","/","-", "*"); /* aqui indico os caracteres que desejo remover */
$cpf = str_replace($chars, "", $_POST['cpf']); /* através de str_replace insiro somente os números invés de caracteres */
$cnpj = str_replace($chars, "", $_POST['cnpj']);
$telefone = str_replace($chars, "", $_POST['telefone']);
You want a mask when typing or just to display?
– rray
I want to record this data in a local database, to later do a data collection and form a table.
– Maicom Rodeghiero
Will that helps?
– Wallace Maxters