【问题标题】:setting Password pattern for validation of Password in android [duplicate]在android中设置密码模式以验证密码[重复]
【发布时间】:2017-01-12 10:10:39
【问题描述】:

我想在 android 中创建包含以下内容的密码模式

  • 大写字符
  • 小写字符
  • 特殊字符
  • 号码
  • 至少 8 位数字。

我用过html5密码模式

String password_pattern = "(?=^.{8,}$)((?=.*\\d)|(?=.*\\W+))(?![.\\n])(?=.*[A-Z])(?=.*[a-z]).*$";

但它不起作用。

【问题讨论】:

    标签: android validation android-layout android-edittext password-protection


    【解决方案1】:

    试试下面的正则表达式,它可以满足你的需要,

    1.大写字母

    2.小写字母

    3.特殊字符

    4.数字

    5.最少8位

    ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$
    

    检查此链接:

    https://regex101.com/r/S7cd5A/1

    【讨论】:

    • 甚至不接受有效密码。
    • @ManXoor 检查链接是否有效。
    【解决方案2】:

    你可以用这个。

    private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})";
    

    图案说明

      (?=.*\d)      #   must contains one digit from 0-9
      (?=.*[a-z])   #   must contains one lowercase characters
      (?=.*[A-Z])   #   must contains one uppercase characters
      (?=.*[@#$%])   #   must contains one special symbols in the list "@#$%"
                  . #   match anything with previous condition checking
      {6,20}        #   length at least 6 characters and maximum of 20
    

    你可以这样使用

    public boolean validate(final String password){
    
            return PASSWORD_PATTERN.matches(password);
    }
    

    详情请Check this

    【讨论】:

      猜你喜欢
      • 2017-11-27
      • 2020-08-16
      • 2019-07-02
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多