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 }
  • 相关阅读:
    BUPT复试专题—最小距离查询(2013)
    BUPT复试专题—中序遍历序列(2013)
    BUPT复试专题—统计节点个数(2013)
    BUPT复试专题—日期(2013)
    BUPT复试专题—内存分配(2014-2)
    BUPT复试专题—图像识别(2014-2)
    Catch That Cow(BFS)
    Pet(hdu 4707 BFS)
    Knight Moves(BFS,走’日‘字)
    Lost Cows(BIT poj2182)
  • 原文地址:https://www.cnblogs.com/yangchengdebokeyuan/p/15406523.html
Copyright © 2011-2022 走看看