// 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 error; *() {} *(S *rawInput) {} // needs rawInput run { filtered = dropPrefix("+", dropSpecialChars(rawInput)); if (!isAllDigits(filtered)) ret with error = "Bad characters"; splitLocal(); } S dropSpecialChars(S s) { ret replaceAll(s, "[\\s\\(\\)\\-]", ""); } void splitLocal { S countryPart = longestPrefixInNavigableSet(filtered, navigableKeys(countryDialCodes_rawNumbersTreeMultiMap())); if (countryPart == null) ret with error = "Invalid country code"; dialCodes = countryDialCodes_rawNumbersTreeMultiMap().get(countryPart); localPart = dropPrefix(countryPart, filtered); if (l(filtered) < 7) ret with error = "Phone number too short"; else if (l(filtered) > 15) ret with error = "Phone number too long"; valid = true; } }