Therefore, we need to clarify how many number segments have been opened. The country number segments are allocated as follows:
Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188
China Unicom: 130, 131, 132, 152, 155, 156, 185, 186
China Telecom: 133, 153, 180, 189 (1349 Weitong)
Now we can test the regular expression matching,
Import java. io. IOException;
Import java. util. regex. Matcher;
Import java. util. regex. Pattern;
Public class ClassPathResource {
Public static boolean isMobileNO (String mobiles ){
Pattern p = Pattern. compile ("^ (13 [0-9]) | (15 [^ 4, \ D]) | (18 [-9]) \ d {8} $ ");
Matcher m = p. matcher (mobiles );
System. out. println (m. matches () + "---");
Return m. matches ();
}
Public static void main (String [] args) throws IOException {
System. out. println (ClassPathResource. isMobileNO ("12016155153 "));
}
}
Method 2:
Import java. util. regex. Matcher;
Import java. util. regex. Pattern;
String value = "mobile phone number ";
String regExp = "^ [1] ([3] [0-9] {1} | 59 | 58 | 88 | 89) [0-9] {8} $ ";
Pattern p = Pattern. compile (regExp );
Matcher m = p. matcher (value );
Return m. find (); // boolean
Method 3:
String check = "^ ([a-z0-9A-Z] + [-|.]?) + [A-z0-9A-Z] @
([A-z0-9A-Z] + (-[a-z0-9A-Z] + )?.) + [A-zA-Z] {2,} $ ";
Pattern regex = Pattern. compile (check );
Matcher matcher = regex. matcher (email );
Flag = matcher. matches ();
} Catch (Exception e ){
Flag = false;
}
Return flag;
}
/**
* Verify the mobile phone number
* @ Param mobiles
* @ Return [0-9] {5, 9}
*/
Public static boolean isMobileNO (String mobiles ){
Boolean flag = false;
Try {
Pattern p = Pattern. compile ("^ (13 [0-9]) | (15 [^ 4, D]) | (18 [-9]) d {8} $ ");
Matcher m = p. matcher (mobiles );
Flag = m. matches ();
} Catch (Exception e ){
Flag = false;
}
Return flag;
}
Public static boolean isNum (String number ){
Boolean flag = false;
Try {
Pattern p = Pattern. compile ("^ [0-9] {5} $ ");
Matcher m = p. matcher (number );
Flag = m. matches ();
} Catch (Exception e ){
Flag = false;
}
Return flag;
}
}