Mais uma post sobre JQuery, Agora é sobre mascara para campos texto usando JQuery.
Em seu código declare as bibliotecas JQuery
<script src="Jquery_JS/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="Jquery_JS/jquery.maskedinput.min.js" type="text/javascript"></script>
Coloque um estilo.
<style>
label, input { font-size: 20px; padding: 10px; float: left; clear: both; } input { border: 1px solid #333;
</style>
Se precisar criar alguma mascara siga o exemplo abaixo é pratico e fácil!
jQuery(function($){ $("#campoData").mask("99/99/9999"); $("#campoTelefone").mask("(999) 999-9999"); $("#campoSenha").mask("***-****"); $("#CPF").mask("999.999.999-99");
<input type="text" class="cpf" name="cpf" value="" />
<input type="text" class="tel" name="" value="" />
<input type="text" class="date" name="" value="" />
Se for a função para somente aceitar formato de cpf
/***************************** VALIDA O CPF *****************************/ function valCpf($cpf){ $cpf = preg_replace('/[^0-9]/','',$cpf); $digitoA = 0; $digitoB = 0; for($i = 0, $x = 10; $i <= 8; $i++, $x--){ $digitoA += $cpf[$i] * $x; } for($i = 0, $x = 11; $i <= 9; $i++, $x--){ if(str_repeat($i, 11) == $cpf){ return false; } $digitoB += $cpf[$i] * $x; } $somaA = (($digitoA%11) < 2 ) ? 0 : 11-($digitoA%11); $somaB = (($digitoB%11) < 2 ) ? 0 : 11-($digitoB%11); if($somaA != $cpf[9] || $somaB != $cpf[10]){ return false; }else{ return true; } }
Nenhum comentário:
Postar um comentário