Доброй ночи. Подскажите, пожалуйста ТОЛЬКО НЕ РЕШЕНИЕ!!! Понимаю что через регулярку проще, но я почти день искал как найти способы проверить через регулярку в Шилтде вообще мало написано, а по статьям нашел не очень много примеров та что сделал по "дедовски"
package com.javarush.task.task22.task2212;
/*
Проверка номера телефона
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static boolean checkTelNumber(String telNumber) {
// try {
if(telNumber!=null||!telNumber.equals("")||telNumber.length()-1>8) {
if (telNumber.startsWith("+")) {
if (telNumber.indexOf("(") != -1 && telNumber.indexOf(")") != -1) {
String word = telNumber.substring(telNumber.indexOf("("), telNumber.indexOf(")"));
if (word.length() - 1 == 3) {
String r = telNumber.replaceFirst("\\({1}", "");
String rr = r.replaceFirst("\\){1}", "");
String rrr = rr.replaceFirst("\\+{1}", "");
if (rrr.matches("\\d{12}$")) {
// System.out.println("w");
return true;
}
}
} else {
if (telNumber.matches("\\+\\d{12}")) {
// System.out.println("w");
return true;
}
}
} else if (telNumber.matches("\\d.*")) {
if (telNumber.indexOf("(") != -1 && telNumber.indexOf(")") != -1) {
String word = telNumber.substring(telNumber.indexOf("("), telNumber.indexOf(")"));
if (word.length() - 1 == 3) {
String r = telNumber.replaceFirst("\\({1}", "");
String rr = r.replaceFirst("\\){1}", "");
if (rr.matches("\\d{10}$")) {
// System.out.println("w");
return true;
}
}
} else if (telNumber.matches("\\d{10}$")) {
// System.out.println("w");
return true;
}
} else if (telNumber.startsWith("(")) {
if (telNumber.indexOf("(") != -1 && telNumber.indexOf(")") != -1) {
String word = telNumber.substring(telNumber.indexOf("("), telNumber.indexOf(")"));
if (word.length() - 1 == 3) {
String r = telNumber.replaceFirst("\\({1}", "");
String rr = r.replaceFirst("\\){1}", "");
if (rr.matches("\\d{10}$")) {
// System.out.println("w");
return true;
}
}
}
}
}
// }catch (StringIndexOutOfBoundsException h)
// {
// System.out.println("yy");
// return false;
// }
// System.out.println("yy");
return false;
}
public static void main(String[] args) {
}
}
telNumber.length()-1>8Не логичнее ли будетtelNumber.length() > 9?