From 049e8b181c440341428913e62c4ca3ea3a52a058 Mon Sep 17 00:00:00 2001 From: 01samiksha <01samiksha@gmail.com> Date: Wed, 10 Oct 2018 21:51:28 +0530 Subject: [PATCH] Added telephone number validator --- tele_validator.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tele_validator.cpp diff --git a/tele_validator.cpp b/tele_validator.cpp new file mode 100644 index 00000000..b77be595 --- /dev/null +++ b/tele_validator.cpp @@ -0,0 +1,29 @@ +#include +#include +using namespace std; + +int main() +{ + string n; + int flag = 0; + cout << "Enter telephone number: "; + cin >> n; + cout << endl; + // cout << n; + + if(n.size() == 10) + { + for (int i = 0; i < 10; ++i) + if(!isdigit(n[i])) + flag = 1; + + if(flag == 0) + cout << "Number is valid."; + else + cout << "Invalid number"; + } + + else + cout << "Invalid number"; + +} \ No newline at end of file