Regular expressions determine which carrier the phone number belongs to

Source: Internet
Author: User

#移动号段 1340-1348|135-139|147|150-152|1571-1572|1574|158-159|182|183|187|188

^1 (34[0-8]| ( 3[5-9]|47|5[0-2]|57[124]|5[89]|8[2378] \\d) \\d{7}$


#联通号段 130|131|132|145|155|156|185|186

^1 (3[0-2]|45|5[56]|8[56]) \\d{8}$


#电信号段 133|153|180|189

^1 (33|53|8[09]) \\d{8}$

<summary>
Return mobile phone number of the carrier, 1 mobile 2 Unicom 3 Telecom
</summary>
<param name= "mobile" ></param>
<returns></returns>
public static int Getmobiletype (string mobile)
{
if (!string. Isnullorwhitespace (MOBILE))
{
String ydexp = "^1 (34[0-8]| ( 3[5-9]|47|5[0-2]|57[124]|5[89]|8[2378] \\d) \\d{7}$ ";
String ltexp = "^1 (3[0-2]|45|5[56]|8[56]) \\d{8}$";
String dxexp = "^1 (33|53|8[09]) \\d{8}$";

Regex reg = new regex (YDEXP);
if (Reg. IsMatch (MOBILE))
{
return 1;
}
reg = new Regex (LTEXP);
if (Reg. IsMatch (MOBILE))
{
return 2;
}
reg = new Regex (DXEXP);
if (Reg. IsMatch (MOBILE))
{
return 3;
}
}
return 0;
}

Results sent by Get mode
private static string dogetrequest (string url)
{
HttpWebRequest Hwrequest;
HttpWebResponse Hwresponse;

String strresult = String. Empty;
Try
{
Hwrequest = (System.Net.HttpWebRequest) webrequest.create (URL);
Hwrequest.timeout = 5000;
Hwrequest.method = "GET";
Hwrequest.contenttype = "application/x-www-form-urlencoded";
}
catch (System.Exception err)
{
Writeerrlog (Err. ToString ());
return strresult;
}

Get response
Try
{
Hwresponse = (HttpWebResponse) hwrequest.getresponse ();
StreamReader Srreader = new StreamReader (Hwresponse.getresponsestream (), encoding.ascii);
strresult = Srreader.readtoend ();
Srreader.close ();
Hwresponse.close ();
}
catch (System.Exception err)
{
Writeerrlog (Err. ToString ());
}

return strresult;
}

Post Invocation instance:

string param = string. Format ("spidxxx={0}&sppasooosword={1}&dc=15&dassssm={2}", spid, SPPW, content);
byte[] btemp = Encoding.ASCII.GetBytes (param);
result = Dopostrequest (URL, btemp);

Post method sent results
public static string dopostrequest (string URL, byte[] bdata)
{
System.Net.HttpWebRequest hwrequest;
System.Net.HttpWebResponse Hwresponse;
String strresult = String. Empty;

if (string. Isnullorwhitespace (URL) | | Bdata = = null)
{
return strresult;
}

Try
{
Hwrequest = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (URL);
Hwrequest.timeout = 5000;
Hwrequest.method = "POST";
Hwrequest.contenttype = "application/x-www-form-urlencoded";
Hwrequest.contentlength = Bdata.length;

System.IO.Stream smwrite = Hwrequest.getrequeststream ();
Smwrite.write (bdata, 0, bdata.length);
Smwrite.close ();
}
catch (System.Exception err)
{
Return "SMS Call exception 1,exception =" + Err. ToString ();
}

Get response
Try
{
Hwresponse = (HttpWebResponse) hwrequest.getresponse ();
StreamReader Srreader = new StreamReader (Hwresponse.getresponsestream (), encoding.ascii);
strresult = Srreader.readtoend ();
Srreader.close ();
Hwresponse.close ();
}
catch (System.Exception err)
{
Return "SMS Call exception 2,exception =" + Err. ToString ();
}

return strresult;
}

Character encoded into hex
private static string encodehexstr (int datacoding, string realstr)
{
String strhex = "";
Try
{
byte[] Bytsource = null;
if (datacoding = = 15)
{
Bytsource = encoding.getencoding ("GBK"). GetBytes (REALSTR);
}
else if (datacoding = = 8)
{
Bytsource = Encoding.BigEndianUnicode.GetBytes (REALSTR);
}
Else
{
Bytsource = Encoding.ASCII.GetBytes (REALSTR);
}
for (int i = 0; i < bytsource.length; i++)
{
Strhex = Strhex + bytsource[i]. ToString ("X2");

}
}
catch (System.Exception err)
{
Writeerrlog (Err. ToString ());
}
return strhex;
}
Hex code reverts to characters
private static string decodehexstr (int datacoding, string hexstr)
{
String strreturn = "";
Try
{
int len = HEXSTR.LENGTH/2;
byte[] bytsrc = new Byte[len];
for (int i = 0; i < len; i++)
{
string s = hexstr.substring (i * 2, 2);
Bytsrc[i] = Byte.parse (s, System.Globalization.NumberStyles.AllowHexSpecifier);
}

if (datacoding = = 15)
{
Strreturn = encoding.getencoding ("GBK"). GetString (BYTSRC);
}
else if (datacoding = = 8)
{
Strreturn = Encoding.BigEndianUnicode.GetString (BYTSRC);
}
Else
{
Strreturn = System.Text.ASCIIEncoding.ASCII.GetString (BYTSRC);
}
}
catch (System.Exception err)
{
Writeerrlog (Err. ToString ());

}
return strreturn;
}

Regular expressions determine which carrier the phone number belongs to

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.