private void MaskTBPhone_MaskInputRejected(object sender, EventArgs e) //Проверка тел. на корректность { if (CheckString.Phone(maskTBPhone.Text)) { maskTBPhone.BackColor = Color.LightGreen; } else if (maskTBPhone.Text.Replace("+7(", "").Replace(")", "").Replace("-", "").Replace(" ", "") == "") { maskTBPhone.BackColor = Color.Snow; } else { maskTBPhone.BackColor = Color.LightCoral; } }
public void PhoneTest() { bool actual; Dictionary <string, bool> testPhone = new Dictionary <string, bool>(); testPhone.Add("", false); testPhone.Add("qwahfynfjndy", false); testPhone.Add("3664069395", false); testPhone.Add("+7(909) 176-92-36", true); testPhone.Add("+7(909) 176-92-3 ", false); testPhone.Add("+7(909) 176-92- ", false); foreach (string element in testPhone.Keys) { actual = CheckString.Phone(element); Assert.AreEqual(testPhone[element], actual, "Строка на входе = \"" + element + "\""); } }