asp.net 获取手机号码

来源:互联网 发布:淘宝店铺活动方案 编辑:程序博客网 时间:2024/05/22 13:38
/// <summary>
/// 获取手机号码
/// </summary>
public static string GetMobile()
{
string mobile = string.Empty;

if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["DEVICEID"]))
{
mobile = HttpContext.Current.Request.ServerVariables["DEVICEID"];
}
if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_UP_SUBNO"]))
{
mobile = HttpContext.Current.Request.ServerVariables["HTTP_X_UP_SUBNO"];
}
if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_NETWORK_INFO"]))
{
mobile = HttpContext.Current.Request.ServerVariables["HTTP_X_NETWORK_INFO"];
}
if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_UP_CALLING_LINE_ID"]))
{
mobile = HttpContext.Current.Request.ServerVariables["HTTP_X_UP_CALLING_LINE_ID"];
}

if (!string.IsNullOrEmpty(mobile))
{
const string pattern = @"1[358]\d{9}";
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(pattern);
System.Text.RegularExpressions.Match m = r.Match(mobile);
if (m.Success)
{
mobile = m.Value;
}
}
return mobile;
}
原创粉丝点击