// see https://howtodoinjava.com/java/regex/java-regex-validate-international-phone-numbers/ sclass InternationalPhoneValidator { S rawInput; S filtered; L dialCodes; // might be multiple countries with same code 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 = longestPrefixInNavigableSet(filtered, keys((TreeMap>) countryDialCodes_rawNumbersTreeMultiMap().data)); if (countryPart == null) ret; dialCodes = countryDialCodes_rawNumbersTreeMultiMap().get(countryPart); localPart = dropPrefix(countryPart, filtered); valid = l(filtered) >= 7 && l(filtered) <= 15; } }