VerifyUser(手机号和密码的正则验证)

package com.example.ggq.gaoguoqing20180811.utils;

import android.text.TextUtils;

import java.util.regex.Pattern;

public class VerifyUser {
    public static boolean isMobileNO(String mobiles) {

      /*

      移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188

      联通:130、131、132、152、155、156、185、186

      电信:133、153、180、189、(1349卫通)

      总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9

      */

        String telRegex = "[1][358]\\d{9}";//"[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。

        if (TextUtils.isEmpty(mobiles)) return false;

        else return mobiles.matches(telRegex);

    }
    public static boolean isPasswordNo(String pwd){
        Pattern z1_ = Pattern.compile("^(?=.*?[a-z])(?=.*?[0-9])[a-zA-Z0-9_]{6,16}$");
        boolean b = z1_.matcher(pwd).matches();
        return b;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42470335/article/details/81609644