Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text.RegularExpressions;
- static void Main(string[] args)
- {
- string mobileRegex = @"^\d{10}$";
- string emailRegex = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
- string nameRegex = @"^[a-zA-Z\s]+$";
- bool exitRequested = false;
- while (!exitRequested)
- {
- Console.WriteLine("Choose what you want to validate:");
- Console.WriteLine("1. Name");
- Console.WriteLine("2. Email");
- Console.WriteLine("3. Mobile Number");
- Console.WriteLine("4. Exit");
- int choice;
- if (!int.TryParse(Console.ReadLine(), out choice) || choice < 1 || choice > 4)
- {
- Console.WriteLine("Invalid choice. Please choose a number between 1 and 4.");
- continue;
- }
- string userInput;
- switch (choice)
- {
- case 1:
- Console.WriteLine("Enter name:");
- userInput = Console.ReadLine();
- Console.WriteLine("Name - Valid: " + Regex.IsMatch(userInput, nameRegex));
- break;
- case 2:
- Console.WriteLine("Enter email address:");
- userInput = Console.ReadLine();
- Console.WriteLine("Email - Valid: " + Regex.IsMatch(userInput, emailRegex));
- break;
- case 3:
- Console.WriteLine("Enter mobile number:");
- userInput = Console.ReadLine();
- Console.WriteLine("Mobile Number - Valid: " + Regex.IsMatch(userInput, mobileRegex));
- break;
- case 4:
- exitRequested = true;
- break;
- }
- }
- Console.WriteLine("Exiting program...");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement