zoukankan      html  css  js  c++  java
  • java判断字符必须包含大写字母、小写字母、数字、特殊符号且10位及以上

    运用正则判断密码必须包含大写字母、小写字母、数字、特殊符号且10及以上

     1 package com.test.tokenserver.util;
     2 
     3 
     4 public class test {
     5 //    public static final String PW_PATTERN = "^(?![A-Za-z0-9]+$)(?![a-z0-9\W]+$)(?![A-Za-z\W]+$)(?![A-Z0-9\W]+$)[a-zA-Z0-9\W]{10,}$";
     6 
     7     public static void main(String[] args) {
     8         System.out.println(checkPswd(null));
     9         System.out.println(checkPswd(""));
    10         System.out.println(checkPswd("123456789987"));
    11         System.out.println(checkPswd("asdfghjklb"));
    12         System.out.println(checkPswd("ASDFGHJKLB"));
    13         System.out.println(checkPswd("<>?:;'/.,;;,,,...@#$^^%^&*("));
    14         System.out.println(checkPswd("AaaaaBbbbb"));
    15         System.out.println(checkPswd("111111Aaaa"));
    16         System.out.println(checkPswd("11111.Aaa"));
    17         System.out.println(checkPswd("11111.Aaaa"));
    18 
    19     }
    20 
    21     /***
    22      *
    23      * @author Y.C
    24      * @date 2021-10-14 13:33:28
    25      * java判断字符是否包含大写字母、小写字母、数字、特殊符号
    26      * (不是字母,数字,下划线,汉字的字符)的10位及以上
    27      *
    28      */
    29     public static final String PW_PATTERN = "^(?![A-Za-z0-9]+$)(?![a-z0-9\W]+$)(?![A-Za-z\W]+$)(?![A-Z0-9\W]+$)[a-zA-Z0-9\W]{10,}$";
    30     public static final boolean checkPswd(String pswd){
    31         boolean falg = false;
    32         try {
    33             if (null==pswd&&pswd.isEmpty()&&pswd.length()>9){
    34                 return  falg;
    35             }
    36             //不全是特殊符号 不全是数字 不全是字母 不全是大写 不全是小写
    37             if (pswd.matches(PW_PATTERN)){
    38                 falg = true;
    39             }
    40 
    41         } catch (Exception e) {
    42             falg = false;
    43         }
    44         return  falg;
    45     }
    46  
    47 }
  • 相关阅读:
    Revolving Digits[EXKMP]
    字符加密Cipher(bzoj 1031)
    Hotaru's problem
    1089 最长回文子串 V2(Manacher算法)
    3172: [Tjoi2013]单词
    3689: 异或之
    3942: [Usaco2015 Feb]Censoring [KMP]
    2795: [Poi2012]A Horrible Poem
    GT考试(bzoj 1009)
    NOIP2016提高组解题报告
  • 原文地址:https://www.cnblogs.com/yangchengdebokeyuan/p/15406523.html
Copyright © 2011-2022 走看看