【问题标题】:Validating a phone number using ASP.NET and the Twilio API使用 ASP.NET 和 Twilio API 验证电话号码
【发布时间】:2012-07-23 07:32:41
【问题描述】:

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

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

【问题讨论】:

    标签: asp.net twilio


    【解决方案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;
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多