|
@@ -8,6 +8,8 @@ import android.text.TextUtils;
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.RequiresPermission;
|
|
import androidx.annotation.RequiresPermission;
|
|
@@ -24,7 +26,7 @@ import static android.Manifest.permission.READ_PHONE_STATE;
|
|
* </pre>
|
|
* </pre>
|
|
*/
|
|
*/
|
|
public final class PhoneUtils {
|
|
public final class PhoneUtils {
|
|
-
|
|
|
|
|
|
+ public static final String MOBLIE_PHONE_PATTERN = "^[1][0-9][0-9]{9}$";
|
|
private PhoneUtils() {
|
|
private PhoneUtils() {
|
|
throw new UnsupportedOperationException("u can't instantiate me...");
|
|
throw new UnsupportedOperationException("u can't instantiate me...");
|
|
}
|
|
}
|
|
@@ -40,6 +42,18 @@ public final class PhoneUtils {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 通过正则验证是否是合法手机号码
|
|
|
|
+ *
|
|
|
|
+ * @param phoneNumber 待验证的手机号码
|
|
|
|
+ * @return 验证结果
|
|
|
|
+ */
|
|
|
|
+ public static boolean isMobile(String phoneNumber) {
|
|
|
|
+ Pattern p = Pattern.compile(MOBLIE_PHONE_PATTERN);
|
|
|
|
+ Matcher m = p.matcher(phoneNumber);
|
|
|
|
+ return m.matches();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* Return the unique device id.
|
|
* Return the unique device id.
|
|
* <p>If the version of SDK is greater than 28, it will return an empty string.</p>
|
|
* <p>If the version of SDK is greater than 28, it will return an empty string.</p>
|
|
* <p>Must hold {@code <uses-permission android:name="android.permission.READ_PHONE_STATE" />}</p>
|
|
* <p>Must hold {@code <uses-permission android:name="android.permission.READ_PHONE_STATE" />}</p>
|