// see https://howtodoinjava.com/java/regex/java-regex-validate-international-phone-numbers/ sclass InternationalPhoneValidator { S rawInput; S filtered; CountryDialCode dialCode; S countryPart, localPart; bool valid; *() {} *(S *rawInput) {} // needs rawInput run { filtered = dropSpecialChars(rawInput); splitLocal(); } S dropSpecialChars(S s) { ret replaceAll(s, "[\\s\\(\\)\\-]", ""); } void splitLocal { S countryPart = longestPrefixInTreeSet(filtered, countryDialCodes_rawNumbersTreeMultiMap()); if (countryPart == null) ret; CountryDialCode dialCode = countryDialCodes_rawNumbersTreeMultiMap().get(countryPart); localPart = dropPrefix(countryPart, filtered); valid = l(filtered) >= 7 && l(filtered) <= 15; } }