public void IsValidPhoneNumber() { string[] phones = { "+7(985)531-08-68", "8(3519)454-54-541", "8(800)454-54-54", "8(800)8455412", "8(3519)454-54-54", "" }; for (int i = 0; i < phones.Length; ++i) { var currentValue = phones[i]; if (i % 2 == 0) { Assert.AreEqual(UserInputValidator.IsValidPhoneNumber(currentValue), true); } else { Assert.AreEqual(UserInputValidator.IsValidPhoneNumber(currentValue), false); } } }
public string ReadPhoneNumberWithHint(string hint) { System.Console.WriteLine(hint); var format = "[+7|7|8]([ddd|dddd])ddd-dd-dd"; var phone = ReadLineWithHint($"Enter the phone number in this format {format}: "); while (!UserInputValidator.IsValidPhoneNumber(phone)) { phone = ReadLineWithHint($"Please enter a valid phone number in this format {format}!"); } System.Console.WriteLine(); return(phone); }