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 に答える