Advertisement
hackthecode

Input Phone Number Formatting

Nov 10th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. class Tel
  4. {
  5.     public static void Main()
  6.     {
  7.         string tel = "";
  8.         Console.Write("Tel. +359 ");
  9.         ConsoleKeyInfo key;
  10.  
  11.         do
  12.         {
  13.             key = Console.ReadKey(true);
  14.  
  15.             if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
  16.             {
  17.                 tel += key.KeyChar;
  18.                 double telForm = double.Parse(tel);
  19.                 Console.Clear();
  20.                 Console.Write("Tel. +359 {0:### ## ## ##}", telForm);
  21.             }
  22.             else
  23.             {
  24.                 if (key.Key == ConsoleKey.Backspace && tel.Length > 0)
  25.                 {
  26.                     tel = tel.Substring(0, (tel.Length - 1));
  27.                     Console.Write("\b \b");
  28.                 }
  29.             }
  30.         } while (key.Key != ConsoleKey.Enter);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement