1: using System;
2: using System.Collections.Generic;
3: using system.linq;
4: using system.text;
5:
6: namespace ankeedu.tools
7: {
8:
9: // <summary>
:/ // phone number help class
One : // author:Andrew.He
:/ // Given a phone number, return to the network where the phone number segment belongs
// / </summary>
: public class Phonehelper
: {
Mobileregex : Regular expression for#region detection number
+ / / <summary>
: Regular expression of /// detection number
// / </summary>
: privateconststring@ "(0?1\d{10)}";
: #endregion
:
P : #region keyvalues mobile phone number segment set, Phonetype.mobile mobile phonetype.unicom Unicom Phonetype.telecom Telecom
:/ / <summary>
* / //mobile phone number segment set, Phonetype.mobile mobile phonetype.unicom unicom phonetype.telecom Telecom
// / </summary>
: privatestaticnew list<phonekeyvalue> ()
: {
: new phonekeyvalue ("1340", Phonetype.mobile),
: new phonekeyvalue ("1341", Phonetype.mobile),
: new phonekeyvalue ("1342", Phonetype.mobile),
: new phonekeyvalue ("1343", Phonetype.mobile),
: new phonekeyvalue ("1344", Phonetype.mobile),
: new phonekeyvalue ("1345", Phonetype.mobile),
: new phonekeyvalue ("1346", Phonetype.mobile),
: new phonekeyvalue ("1347", Phonetype.mobile),
Panax notoginseng : new phonekeyvalue ("1348", Phonetype.mobile),
: new phonekeyvalue ("135", Phonetype.mobile),
: new phonekeyvalue ("136", Phonetype.mobile),
Max : new Phonekeyvalue ("137", Phonetype.mobile),
In : new phonekeyvalue ("138", Phonetype.mobile),
: new Phonekeyvalue ("139", Phonetype.mobile),
: new phonekeyvalue ("147", Phonetype.mobile),
: new phonekeyvalue ("Phonetype.mobile"),
: new phonekeyvalue ("151", Phonetype.mobile),
: new phonekeyvalue ("Phonetype.mobile"),
A : new phonekeyvalue ("157", Phonetype.mobile),
Phonekeyvalue : new ("158", Phonetype.mobile),
by : new phonekeyvalue ("159", Phonetype.mobile),
: new phonekeyvalue ("182", Phonetype.mobile),
Wuyi: new Phonekeyvalue ("183", Phonetype.mobile),
Phonekeyvalue : new ("184", Phonetype.mobile),
: new phonekeyvalue ("187", Phonetype.mobile),
Wu : new phonekeyvalue ("188", Phonetype.mobile),
: new phonekeyvalue ("phonetype.unicom"),
Phonekeyvalue : new ("131", phonetype.unicom),
£ º new phonekeyvalue ("phonetype.unicom"),
: new Phonekeyvalue ("145", phonetype.unicom),
: new phonekeyvalue ("155", phonetype.unicom),
: new phonekeyvalue ("156", phonetype.unicom),
Section : new Phonekeyvalue ("185", phonetype.unicom),
: new Phonekeyvalue ("186", phonetype.unicom),
Phonekeyvalue : new ("133", phonetype.telecom),
: new phonekeyvalue ("1349", phonetype.telecom),
: new Phonekeyvalue ("153", phonetype.telecom),
Phonekeyvalue : new ("phonetype.telecom"),
Phonekeyvalue : new ("181", phonetype.telecom),
: new phonekeyvalue ("189", phonetype.telecom)
: };
: #endregion
:
Getphonetype : #region Check whether the mobile phone number is the corresponding phone category
// <summary>
A : // Check whether the mobile phone number is the corresponding phone category
:/ / </summary>
:/ // <param name= "Phoneno" ></param>
// / <returns></returns>
Phonetype : public static getphonetype (string Phoneno)
: {
A : if (! Isphoneno (Phoneno))
Bayi: {
Phonetype.notphoneno : return ;
: }
A :
: var model = keyvalues.where (x = Phoneno.startswith (X.key)). FirstOrDefault ();
: ifnull)
: {
A : return model. Phonetypevalue;
: }
:
: return phonetype.other;
: }
: #endregion
94:
#region Isphoneno detection number is mobile phone number
// / <summary>
* / / Whether the test number is a mobile phone number
98: // </summary>
:/ // <param name= "Phoneno" ></param>
: // <returns></returns>
101: Private Static BOOL Isphoneno (string Phoneno)
102: {
103: if (string. IsNullOrEmpty (Phoneno))
104: {
: return false;
106: }
107:
108: return System.Text.RegularExpressions.Regex.Match (Phoneno, Mobileregex,
109: System.Text.RegularExpressions.RegexOptions.IgnoreCase |
: System.Text.RegularExpressions.RegexOptions.ECMAScript). Success;
111: }
: #endregion
113: }
:
: #region Phonekeyvalue Mobile phone number segment entity
: // <summary>
117: /// phone number segment entity
118: // </summary>
119: Public class Phonekeyvalue
: {
121: Public Phonekeyvalue (string key,phonetype type)
122: {
123: this. Key = key;
124: this. Phonetypevalue = type;
: }
126: Public string key {get; set;}
127: Public Phonetype Phonetypevalue {get; set;}
: }
129: #endregion
:
131: #region Phonetype Number Category
: // <summary>
133: /// number category
134: // </summary>
135: Public enum Phonetype
136: {
137: // <summary>
138: /// not a mobile phone number
139: // </summary>
: Notphoneno,
141: // <summary>
142: // Unknown affiliation, other
143: // </summary>
144: Other,
145: // <summary>
146: // Mobile number
147: // </summary>
148: Mobile,
149: // <summary>
: /// Unicom number
151: // </summary>
: Unicom,
153: // <summary>
154: /// telco number
155: // </summary>
156: Telecom
157: }
158: #endregion
159: }