package javavk import java util regex Pattern public class PhoneChecke

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
package javavk;
import java.util.regex.Pattern;
public class PhoneChecker {
public static void main(String[] args) {
System.out.println(checkPhone("+7 (900)-900-9000"));
System.out.println(checkPhone(" +7 (900)-900-9000"));
System.out.println(checkPhone("+7 (900)-900-9000 "));
System.out.println(checkPhone(""));
}
private static final Pattern checkPhoneRegex = Pattern.compile("^\\+\\d\\s\\(\\d{3}\\)-\\d{3}-\\d{4}$");
public static boolean checkPhone(String phone) {
return checkPhoneRegex.matcher(phone).find();
}
}