用户名密码正则判断
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("正确"); } }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: PHPExcel占用内存过大
- 下一篇: 输入校验一(js实现用户名校验)