import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by Administrator on 2016/9/5. */ public class Testzhengze { public static void main(String[] args) throws Exception { String username="66hh_7777777777777777777777777777777777777777777777777777777"; String password="password"; String regex = "^[A-Za-z0-9_-]{1,60}+$"; String regex1="((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20}+)"; Pattern w=Pattern.compile(regex1); Matcher wk=w.matcher(password); Pattern p = Pattern.compile(regex); Matcher m = p.matcher(username.trim()); boolean tem = m.matches(); boolean pw=wk.matches(); if(tem==false){ System.out.println("用户名输入错误"); } if(pw==false){ System.out.println("密码格式不对"); } System.out.println("正确"); } }
用户名密码正则判断
最新推荐文章于 2023-01-04 15:48:19 发布