using System.Text.RegularExpressions;
string phone = "6158033510";
Console.WriteLine(ValidatePhoneNumberFormat(phone));
public static void SendSms(string phoneNumber, string message)
WebRequest req = WebRequest.Create(string.Format("{0}/sending/messages?format=xml", "https://app.eztexting.com"));
req.ContentType = "application/x-www-form-urlencoded";
using (Stream writeStream = req.GetRequestStream())
byte[] bytes = Encoding.UTF8.GetBytes(string.Format("User={0}&Password={1}&PhoneNumbers={2}&Message={3}",
"hcbluebook", "M@kinM30wsic", phoneNumber, message));
writeStream.Write(bytes, 0, bytes.Length);
using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse())
using (StreamReader reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8))
respBody = reader.ReadToEnd();
if (resp.StatusCode != HttpStatusCode.Created)
throw new Exception(string.Format("Response from SMS gateway was not good: {0} - {1}", resp.StatusCode, respBody));
public static bool ValidatePhoneNumberFormat(string phoneNumber)
return Regex.Match(phoneNumber, @"^([0-9]{10})$").Success;
public static bool ValidateMessageLength(string messsage)
return messsage.Length <= 160;