Máscaras (maskedinput)
Testes de máscaras usando o plugin Masked Input.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
<form action="#">
<legend>Formulário teste</legend>
<label for="cnpj">CNPJ do Estabelecimento:</label>
<input type="text" id="cnpj" />
<label for="cpf">CPF do Representante:</label>
<input type="text" id="cpf" />
<hr>
<p>Plugin | <a href="http://digitalbush.com/projects/masked-input-plugin/" target="_blank">Masked Input</a></p>
</form>
CSS
* { font-family: tahoma, verdana, sans-serif; font-size: 12px; line-height: 100%; }
label { display: block; font-weight: bold; margin: 20px 0 10px 0; }
form { background: #eee; padding: 0 30px 30px; border-radius: 6px; border: 1px solid #ccc; }
input, textarea, select { padding: 7px; }
legend { background: #ddd; padding: 10px 15px; color: #666; }
hr { outline:none; height: 0; border: 0; margin: 15px 0; background: none; border-top: 1px solid #ccc; }
p { color: #888; }
a { color: #48b; }
JavaScript
$(document).ready(function(){
$('#cnpj').mask('99.999.999/9999-99');
$('#cpf').mask('999.999.999-99');
});