Currently, I'm trying to implement validation on user input. The idea is that if a user enters a number between 1 and 10, I want to add a 0
in front of it. For example, if the user inputs 4
, I would like to store the value 04
. While I am comfortable doing this in C#, I am facing challenges when attempting to achieve the same functionality in TypeScript within a component class for my Angular 5 application.
public static void Main(string[] args)
{
List<int> collection = new List<int>();
for (int i = 1; i <= 10; i++)
{
collection.Add(i);
}
Console.WriteLine("Please enter your input below: " + "\n");
string input = Console.ReadLine();
Console.WriteLine();
if (collection.Contains(Convert.ToInt32(input)))
{
Console.WriteLine("True" + "\n");
var result = "0" + input;
Console.WriteLine("Appended Result: " + result);
}
else
{
Console.WriteLine("False");
}
Console.WriteLine();
}
The version of TypeScript I am working with is 2.3.3.0
.