Ругается на последний пункт, хотя добавил уже всевозможные проверки на null. Так все номера проверяет правильно.
package com.javarush.task.task22.task2212;
/*
Проверка номера телефона
*/
public class Solution {
public static boolean checkTelNumber(String telNumber) {
int j = telNumber.replaceAll("\\D", "").length();
if (telNumber == null || telNumber.isEmpty()||telNumber.length()==0) {
return false;
}
else if (j == 12) {
return telNumber.matches("^\\+?\\d*(\\(\\d{3}\\))?\\d*-?\\d+-?\\d+$");
} else if (j == 10) {
return telNumber.matches("^\\d*(\\(\\d{3}\\))?\\d*-?\\d+-?\\d+$");
}
return false;
}
public static void main(String[] args) {
}
}