Exemplo n.º 1
0
        public static bool hasLetters(string myString)
        {
            myString = JeffToolBox.RemoveSpecialCharacters(myString);
            myString = myString.Replace(".", "");

            foreach (var i in myString)
            {
                if ((i < '0' || i > '9'))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public static decimal ReadInterestRate(string message, bool positiveNumber = false, bool acceptZero = true)
        {
            while (true)
            {
                try
                {
                    Console.WriteLine(message);

                    string input = Console.ReadLine();

                    if (string.IsNullOrEmpty(input))
                    {
                        Console.WriteLine("Please enter a number");

                        continue;
                    }

                    input = JeffToolBox.RemoveSpecialCharacters(input);

                    decimal returnValue = decimal.Parse(input);

                    if (positiveNumber == true && returnValue < 0)
                    {
                        Console.WriteLine("Please enter a positive number");

                        continue;
                    }
                    if (acceptZero == false && returnValue == 0)
                    {
                        Console.WriteLine("Please enter a number other than 0");

                        continue;
                    }

                    if ((returnValue * 2 > Decimal.MaxValue) || (returnValue * 3 > Decimal.MaxValue))
                    {
                        Console.WriteLine("---------------- \n \n");
                        Console.WriteLine("Please enter a smaller number, dont be a hacker...");
                        continue;
                    }

                    if (returnValue > 100)
                    {
                        Console.WriteLine("---------------- \n \n");
                        Console.WriteLine("You cant have an interest rate larger than 100%!");
                        Console.WriteLine("Please enter an Interest Rate between 0 - 100.");
                        continue;
                    }


                    return(returnValue);
                }
                catch (ArgumentNullException e)
                {
                    Console.WriteLine("Please enter a value");
                }
                catch (FormatException e)
                {
                    Console.WriteLine("Please enter a numerical value");
                }
                catch (OverflowException e)
                {
                    Console.WriteLine("Please enter a reasonably sized number");
                }
                catch (Exception e)
                {
                    Console.WriteLine("There was an error reading this decimal");
                }
            }
        }