Warning: session_start(): open(/var/lib/php/sessions/sess_qgr80d286hkui427obmsh32869, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// 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 = dropSpecialChars(rawInput);
if (!allDigits(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;
}
}