1

我正在尝试使用下面的代码检查数字是否有效。这行得通吗?

try
    {
        TwilioRest.Account account = new TwilioRest.Account(TwilioRest.TwilioConstants.ACCOUNT_SID, TwilioRest.TwilioConstants.ACCOUNT_TOKEN);
        string strResponse = account.request(String.Format("/{0}/Accounts/{1}/OutgoingCallerIds", TwilioRest.TwilioConstants.API_VERSION, TwilioRest.TwilioConstants.ACCOUNT_SID), "GET");
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(strResponse);
        XmlNode root = xmlDoc.DocumentElement.ChildNodes[0];
        int cont = 0;
        if (root.ChildNodes.Count > 0)
        {
            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                string ss = root.ChildNodes[i].SelectSingleNode("PhoneNumber").ChildNodes[0].Value;
                if (phoneno.Trim() == ss)
                {
                    cont = 1;
                    break;
                }
            }
        }
        if (cont == 0)
        {
            btnSubmit.Visible = true;
        }
    }
    catch (TwilioRest.TwilioRestException ex)
    {
        mpValidatePhone.Show();
        ucMsgPhone.MessageType = MessageType.Error;
        ucMsgPhone.Text = TwilioErrorMessage(ex.ToString());
    }
4

1 回答 1

1

试试这样......

string strResponse = account.request(String.Format("/{0}/Accounts/{1}/OutgoingCallerIds",
            TwilioRest.TiwlioConstants.API_VERSION, TwilioRest.TiwlioConstants.ACCOUNT_SID), "GET");
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(strResponse);
        XmlNode root = xmlDoc.DocumentElement.ChildNodes[0];
        foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes[0])
        {
            string nodeVal = node.SelectSingleNode("PhoneNumber").ChildNodes[0].Value.ToString();
            string fonVal = foneCountryCode + PhoneNumber.Replace("-", "");
            //if (node.SelectSingleNode("PhoneNumber").ChildNodes[0].Value == "+" + PhoneNumber.Replace("-", ""))
            if(nodeVal == fonVal)
            {
                result = true;
                break;
            }
        }
于 2012-07-23T07:51:21.113 回答