Advertisement
RochaNeto

Untitled

Mar 31st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. {if $filename eq 'register' or $filename eq 'cart' or $filename eq 'clientarea'}
  2. <script src='https://www.google.com/recaptcha/api.js'></script>
  3. <script type="text/javascript" src="{$WEB_ROOT}/templates/{$template}/js/valida_cpf_cnpj.js"></script>
  4. <script type="text/javascript" src="{$WEB_ROOT}/templates/{$template}/js/telefone.js"></script>
  5. {literal}
  6. <script>
  7. $(function(){
  8. // Aciona a validação e formatação ao sair do input
  9. $('#customfield58').blur(function(){ // aqui você deve colocar o ID gerado pelo campo personalizado no WHMCS
  10.  
  11. var cpf_cnpj = $(this).val();
  12.  
  13. // Testa a validação e formata se estiver OK
  14. if ( formata_cpf_cnpj( cpf_cnpj ) ) {
  15. $(this).val( formata_cpf_cnpj( cpf_cnpj ) );
  16. $('p.invalido').remove(); // remove o aviso de inválido se existir
  17. } else {
  18. $(this).val("");
  19.  
  20. if ($('p.invalido').length > 0) {
  21.  
  22. } else {
  23. $(this).after( "<p class='invalido' style='color:red;'>CPF ou CNPJ inválido.</p>" ); // adiciona o aviso de inválido se não já existir logo abaixo do campo
  24. }
  25. }
  26.  
  27. });
  28.  
  29. });
  30. </script>
  31.  
  32. <script> //permite apenas números no campo CPF ou CNPJ
  33. $(document).ready(function(){
  34.  
  35. function onlyNumber(fields){
  36. $(fields).unbind('keyup').bind('keyup',function(e){
  37.  
  38. var thisVal = $(this).val();
  39. var tempVal = "";
  40.  
  41. for(var i = 0; i<thisVal.length; i++){
  42. if(RegExp(/^[0-9]$/).test(thisVal.charAt(i))){
  43. tempVal += thisVal.charAt(i);
  44.  
  45. if(e.keyCode == 8){
  46. tempVal = thisVal.substr(0,i);
  47. }
  48. }
  49. }
  50. $(this).val(tempVal);
  51. });
  52. }
  53.  
  54. onlyNumber($('#customfield58')); //aqui adicione o ID gerado pelo campo do WHMCS
  55.  
  56. });
  57.  
  58. </script>
  59. {/literal}
  60. {/if}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement