1

I'm trying to check whether numbers are valid using the code below. Will this work?

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());
    }

1 Answer 1

1

try like this....

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;
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.