#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
bool isAllDigits(const std::string &s) {
for (unsigned char ch : s) {
if (!std::isdigit(ch)) return false;
}
return true;
}
std::string trim(const std::string &s) {
auto first = s.find_first_not_of(" \t\r\n");
if (first == std::string::npos) return "";
auto last = s.find_last_not_of(" \t\r\n");
return s.substr(first, last - first + 1);
}
int main() {
std::string phone;
while (true) {
std::cout << "Enter a 10-digit phone number: ";
std::getline(std::cin, phone);
// Trim whitespace so " " counts as empty and " 1234567890 " is accepted
phone = trim(phone);
if (phone.empty()) {
std::cout << "Input cannot be empty. Please enter the phone number.\n";
continue;
}
if (phone.size() != 10) {
std::cout << "Invalid length. Please enter exactly 10 digits.\n";
continue;
}
if (!isAllDigits(phone)) {
std::cout << "Invalid characters detected. Use digits 0-9 only.\n";
continue;
}
// If we reach here, phone is valid
break;
}
std::cout << "Phone number accepted: " << phone << '\n';
return 0;
}