java--正则--验证

import java.util.*;
import java.util.regex.*;
class FilesDemo2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入6-16位为密码,以大写英文开头 以数字结尾");
String str = sc.next();
String s = "^[A-Z][a-zA-Z0-9]{4,14}\\d$";
Pattern p = Pattern.compile(s);
Matcher m = p.matcher(str);
if(m.matches()){
System.out.println("成功");
}else{
System.out.println("失败");
}
}
}

posted @ 2017-04-19 20:26  负零度  阅读(187)  评论(0编辑  收藏  举报