正则表达式校验密码复杂性的规则

最近做一个项目,需要校验密码复杂性,想了想还是用正则表达式来判断方便快捷;

因密码是数字+字母组成,就只校验数字和字母是否存在;

例:

private String checkDataValid(String account, String pwd, String pwd_confirm) {    
    //正则表达式判断字母数字同时存在并不包含特殊字符
    String reg = "^(?![a-zA-z]+$)(?!\\d+$)(?![!@#$%^&*]+$)[a-zA-Z\\d!@#$%^&*]+$";
    if (TextUtils.isEmpty(account) | TextUtils.isEmpty(pwd) | TextUtils.isEmpty(pwd_confirm))
        return getResources().getString(R.string.null_user_pwd);
    if (pwd.length() < 8) {
        return getResources().getString(R.string.pwd_len_not_less_eight);
    }
    if (!pwd.matches(reg)) {
        return getResources().getString(R.string.pwd_must_num_letter);
    }
    if (!pwd.equals(pwd_confirm))
        return getResources().getString(R.string.not_equal_hint);
    if (account.length() != 11 && !account.contains("@"))
        return getResources().getString(R.string.account_invalid_hint);
    return "";
}

注:如有问题可以回复,看到第一时间分析解决,码农不易,感觉对您有用,帮助到您,可否打赏一杯可乐,在此谢过诸位,愿诸君终成大神,前程似锦~~~

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值