You can do it in several ways, I'll show you the simplest. There is a library of your own that you can "Import" through the 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>
addthisscriptbelowinyourHTMLaswell
<scripttype="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 place the ID for what you indicated in JavaScript. But you can also create a class and refer to $('.cpf').mask('00000-000);
however, you will have to change its input and instead of putting 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 your variables you will have to make a deal to eliminate the points, I will leave a simple example below 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']);