Advertisement
tiagooleite2

Untitled

Nov 15th, 2020
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. package expressaoregular;
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class MascaraValidacaoCPF {
  7.    
  8.     public static boolean ehCPFValido(String cpf) {
  9.         if (cpf == null || cpf.trim().isEmpty()
  10.                 || cpf.trim().length() != 14) {
  11.             return false;
  12.         }
  13.        
  14.         if (cpfContemApenasNumeros(cpf)) {
  15.             return true;
  16.         }
  17.        
  18.         return false;
  19.     }
  20.  
  21.     private static boolean cpfContemApenasNumeros(String cpf) {
  22.         Pattern patternNumero = Pattern.compile("\\d{3}.\\d{3}.\\d{3}-\\d{2}");
  23.         Matcher matcherCPF = patternNumero.matcher(cpf);
  24.        
  25.         if (matcherCPF.find()) {
  26.             return true;
  27.         }
  28.        
  29.         return false;
  30.     }
  31.  
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement