Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package expressaoregular;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class MascaraValidacaoCPF {
- public static boolean ehCPFValido(String cpf) {
- if (cpf == null || cpf.trim().isEmpty()
- || cpf.trim().length() != 14) {
- return false;
- }
- if (cpfContemApenasNumeros(cpf)) {
- return true;
- }
- return false;
- }
- private static boolean cpfContemApenasNumeros(String cpf) {
- Pattern patternNumero = Pattern.compile("\\d{3}.\\d{3}.\\d{3}-\\d{2}");
- Matcher matcherCPF = patternNumero.matcher(cpf);
- if (matcherCPF.find()) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement