コード例 #1
0
        public static void showingData(Person p)
        {
            StandardedMessages.showInfoMessage();  //StandardedMessage class

            Console.WriteLine("Full Name :" + p.FirstName + " " + p.LastName);
            Console.WriteLine("Age :" + p.Age);
            Console.WriteLine("Birthday :" + p.Birthday);

            StandardedMessages.endMessage(); //standardMessage class
        }
コード例 #2
0
        public static IDictionary <string, string> validateData(IDictionary <string, string> person)
        {
            if (person.ContainsKey("fname") == true)
            {
                //Regex.IsMatch(input, @"^[a-zA-Z0-9]+$"); number and letters
                if (!Regex.IsMatch(person["fname"], @"^[a-zA-Z]+$"))
                {
                    Console.WriteLine("You didn't give us a valid First Name!");
                    Console.WriteLine("Try Again");
                    StandardedMessages.endMessage(); //StandardedMessage class
                }
            }
            if (person.ContainsKey("sname") == true)
            {
                if (!Regex.IsMatch(person["sname"], @"^[a-zA-Z]+$"))

                {
                    Console.WriteLine("You didn't give us a valid Last Name!");
                    Console.WriteLine("Try Again");
                    StandardedMessages.endMessage(); //StandardedMessage class
                }
            }
            if (person.ContainsKey("age") == true)
            {
                //int.TryParse(person["age"], out int age)

                if ((int.TryParse(person["age"], out int age) == false) || (person["age"].Count(c => char.IsDigit(c)) > 2)) // only numbers
                {
                    Console.WriteLine("You didn't give us a valid age!");
                    Console.WriteLine("Try Again");

                    StandardedMessages.endMessage(); //StandardedMessage class
                }
            }
            if (person.ContainsKey("bday") == true)
            {
                if (DateTime.TryParse(person["bday"], out DateTime Temp) == false)
                {
                    Console.WriteLine("You didn't give us a valid Birthday!");
                    Console.WriteLine("Try Again");
                    StandardedMessages.endMessage();     //StandardedMessage class
                }
            }

            return(person);
        }