public void validatePhonenum2()
        {
            PhoneValidator phoneValid = new PhoneValidator();

            phoneValid.ValidatePhone("ABC-DEFG");
            bool validphone = phoneValid.ValidatePhone("ABC-DEFG");

            Assert.IsTrue(validphone);
        }
        public void validatePhonenum3()
        {
            PhoneValidator phoneValid = new PhoneValidator();

            phoneValid.ValidatePhone("418-4465987654");
            bool validphone = phoneValid.ValidatePhone("418-4465987654");

            Assert.IsTrue(validphone);
        }
        public void validatePhonenum()
        {
            PhoneValidator phoneValid = new PhoneValidator();

            phoneValid.ValidatePhone("418-4465");
            bool validphone = phoneValid.ValidatePhone("418-4465");

            Assert.IsFalse(validphone);
        }
示例#4
0
        public static bool IsValidPhone(string phone)
        {
            if (Util.IsNullOrEmpty(phone))
            {
                return(false);
            }

            if (!PhoneRegex.IsMatch(phone))
            {
                return(false);
            }

            bool repeat = true;

            for (int i = 0; i < (phone.Length - 6); i++)
            {
                if (phone[i + 6] != '-')
                {
                    if (phone[i + 6] != phone[5])
                    {
                        repeat = false;

                        break;
                    }
                }
            }

            if (repeat)
            {
                return(false);
            }

            if (!PhoneValidator.ValidatePhone(phone))
            {
                return(false);
            }

            return(true);
        }