Write two functions this afternoon, or more general ~~~

xiaoxiao2021-03-06  26

/ ** /

///

/// Generates a random number /// /// generating random numbers /// Specifies a random number string

public

Static

String

Getrandomcode

int

Number

{String [] arrlist = new string [] {"0", "1", "2", "3", "4", "6", "8", "9" , "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", " M "," n "," o "," p "," q "," r "," s "," t "," u "," w "," x "," y "," z " }; Stringbuilder sb = new stringbuilder (""); random random = new random (); for (int i = 0; i

/ ** /

///

/// The judgment number is Unicom, mobile, which is, before using this method, please verify the legality of the number /// rule: the first three is 130-133 Unicom; the first three The bit is 1340-139 or the first four is 1340-1348; the other should be telecom /// /// The number to be judged /// < Returns> Return the corresponding type: 1 represents Unicom; 2 represents mobile; 3 generation Telecom

public

Static

int

GetMobileType

String

Mobile)

{String [] chinaunicom = new string [] {"130", "131", "132", "133"}; string [] chinamobile1 = new string [] {"135", "136", "137", "138", "139"}; string [] chinamobile2 = new string [] {"1340", "1341", "1342", "1343", "1344", "1345", "1346", "1347" , "1348"}; Bool BolchinaUnicom = (Array.indexof (ChinaUnicom, Mobile.Substring (0, 3))> = 0); Bool BolchinAmobile1 = (Array.indexof (chinAmobile1, mobile.substring (0, 3))> = 0); Bool BolchinAmobile2 = (Array.indexof (chinAmobile2)> = 0); if (BolchinaUnicom) Return 1; // Unicom IF (BolchinAmobile1 || BolchinaMobile2) Return 2; // Mobile Return 3; // Other as telecom} Note: There are friends suggest that the second method is better, it is really good, it is true, the new implementation of the second method is attached:

/ ** /

///

/// The judgment number is Unicom, mobile, which is, before using this method, please verify the legality of the number /// rule: the first three is 130-133 Unicom; the first three The bit is 1340-139 or the first four is 1340-1348; the other should be telecom /// /// The number to be judged /// < Returns> Return the corresponding type: 1 represents Unicom; 2 represents mobile; 3 generation Telecom

public

Static

int

GetMobileType

String

Mobile)

{IF (ischinaUnicomnumber (Mobile) Return 1; IF (ischinamobilenumber (mobile)) Return 2; Return 3;

//

Whether it is Unicom's number test

Private

Static

Bool

IschinaUnicomnumber

String

Mobile)

{String Spattern = "^ (130 | 131 | 132 | 133) [0-9] {8}"; BOOL IschinaUnicom = regex.ismatch (Mobile, spattern); return ischinaunicom;} //

Is it a mobile number test

Private

Static

Bool

Ischinamobilenumber (

String

Mobile)

{String Spattern = "(135 | 136 | 137 | 138 | 139 | 1340 | 1341 | 1342 | 1343 | 1344 | 1345 | 1346 | 1347 | 1348) [1-9] {7,8}"; Return Regex. Ismatch (mobile, spattern);

转载请注明原文地址:https://www.9cbs.com/read-69876.html

New Post(0)