using System.Collections.Generic;
using System.Text.RegularExpressions;
static List<Contact> contacts = new List<Contacts>();
public static void Main(string[] args)
Console.WriteLine("1.Register new Person data .");
Console.WriteLine("2.Show person table by alphabet .");
var key = Console.ReadKey();
contacts.Add(MakeContact());
private static Contact MakeContact()
var contact = new Contact();
Console.WriteLine("please enter contact firstName :");
var firstName = Console.ReadLine();
while (string.IsNullOrWhiteSpace(firstName))
Console.WriteLine("firstName must not be empty!");
firstName = Console.ReadLine();
contact.FirstName = firstName;
Console.WriteLine("please enter contact lastName :");
var lastName = Console.ReadLine();
while (string.IsNullOrWhiteSpace(lastName))
Console.WriteLine("lastName must not be empty!");
lastName = Console.ReadLine();
contact.LastName = lastName;
Console.WriteLine("please enter contact address :");
var address = Console.ReadLine();
while (string.IsNullOrWhiteSpace(address))
Console.WriteLine("address must not be empty!");
address = Console.ReadLine();
contact.Address = address;
Console.WriteLine("please enter contact phoneNumber :");
var phoneNumber = Console.ReadLine();
while (string.IsNullOrWhiteSpace(phoneNumber))
Console.WriteLine("phoneNumber must not be empty!");
phoneNumber = Console.ReadLine();
var rgx = new Regex(@"^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$");
if (rgx.IsMatch(phoneNumber))
contact.PhoneNumber = phoneNumber;
throw new Exception("Invalid PhoneNumber input");
contact.CreatedTime =DateTime.Now;
private static void SearchContact()
Console.WriteLine("please enter one character to search or type (all) to show all contact :");
var input = Console.ReadLine();
if (input.Equals("all".ToLower()))
ShowSearchedContact(input);
Console.WriteLine("please press \"Enter\" to go to main menu ");
if (Console.ReadKey().Key == ConsoleKey.Enter)
private static void ShowAllContacts()
Console.WriteLine("there is no contact !");
foreach (var contact in contacts)
private static void ShowSearchedContact(string input)
var isThereContact = false;
var rgx = new Regex($"^{input.ToLower()}|{input.ToUpper()}");
foreach (var contact in contacts)
if (rgx.IsMatch(contact.LastName))
Console.WriteLine("there is no contact !");
private static void PrintContact(Contact contact)
Console.WriteLine($"Name:{contact.FirstName}\t Family:{contact.LastName}\t Tel:{contact.PhoneNumber}\t Address:{contact.Address}\t RegisterYear:{contact.CreatedTime.Date}");