Does anyone have an idea or why this exercise would be useful ?
I mean it's not like you have to churn out prep code and think about the logic of the program (unless you want to go the route of if statements like I started).
Is it worth trying to remember the regex combinations?

package com.codegym.task.task22.task2212;
/*
Phone number verification
*/
public class Solution {
public static boolean checkPhoneNumber(String phoneNumber) {
if (phoneNumber == null) return false;
/*
3) the number may contain 0-2 non-consecutive '-' characters
4) the number may contain 1 pair of matching parentheses, which must be to the left of the '-' characters
5) the parentheses must contain exactly 3 digits
7) the number must end with a digit
1) if the number starts with '+', then it must contain 12 digits
2) if the number starts with a digit or opening parenthesis, then it must contain 10 digits
*/
if (phoneNumber.length() < 10) return false;
if (phoneNumber.contains("+") && phoneNumber.indexOf("+") > 0) return false;
if (phoneNumber.contains("+") && phoneNumber.indexOf("+")==0 && phoneNumber.length() < 12) return false;
if (phoneNumber.contains("[a-z]")) return false;
if (phoneNumber.substring(phoneNumber.length()-1).equals("[a-z]")) return false;
return false;
}
public static void main(String[] args) {
}
}

onlythe points that I am stuck on. I have solved 99% of the problems I have faced this way. After solving, and typically struggling, I had a much better understanding of each of the steps algorithmically in solving the greater problem. At that point I would search for better or more succinct ways of solving the problem, typically with techniques I was unfamiliar with (such as regex). It made a lot more sense to me to see the "advanced techniques" and how they are used to solve all those problems that I had to solve on my own. btw... "advanced techniques" is a poor description. All it is is the evolution of design. The first computers were nothing more than some lights and knobs/switches. Someone decided to give them a screen with text. The first inputs were punchards which someone decided a keyboard would be better. Then someone started doing graphics with computers which turned into graphical operating systems, which led to the mouse to navigate, etc etc etc.digits. When it says the number should have 10/12 digits, the .length() method will not return the correct amount of digits:"+12(324)2-1-".length()equals 12 even though it only contains 7 digits 2) make sure you are checking for invalid chars in the phone number string. Checking for [a-z] are only 26 of the possible ~65000 possible invalid chars. *hint* I would check that it only contains the 14 valid chars instead of the invalid ones.