The project needs to verify whether the user's mobile phone number input is legal. I have found several codes online, but they fail after testing! Finally, I found a piece of code that can be verified. The code seems to be found on a website with many advertisements, I don’t know the author! But thanks to the original author for sharing! Here is the verification source code:
The code copy is as follows:
public static boolean isMobileNO(String mobiles) {
boolean flag = false;
try {
//13*********,15*********,18************
Pattern p = Pattern
.compile("^((13[0-9])|(15[^4,//D])|(18[0,5-9]))//d{8}$");
Matcher m = p.matcher(mobiles);
flag = m.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}