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 MascaraValidacaoTelefone {
- public static boolean ehTelefoneValido(String telefone) {
- if (telefone == null || telefone.trim().isEmpty()) {
- return false;
- }
- Pattern patternTel1 = Pattern.compile("\\(\\d{2}\\)\\s9\\d{4}\\-?\\d{4}");
- Matcher matcherTel1 = patternTel1.matcher(telefone);
- Pattern patternTel2 = Pattern.compile("\\d{2}\\s9\\d{8}");
- Matcher matcherTel2 = patternTel2.matcher(telefone);
- if (matcherTel1.find() || matcherTel2.find()) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement