class RegexDemo{ public static void main(String[]args){ checkQQ(); } static void checkQQ(){ /** *对QQ号进行校验, *要求:5-15位,第一位不能为0,不能有非法字符 */ String QQ = "a01b33333"; if( ! (QQ.length()< 5 || QQ.length() >15)){ if(! QQ.startsWith("0")){ char[] arr= QQ.toCharArray(); boolean flag = true; for(int i =0;i< arr.length;i++){ if( arr[i]<‘0‘ || arr[i] >‘9‘){ flag =false; break; } } if(flag) System.out.println("QQ号:"+QQ); else System.out.println("非法QQ号!"); } else{ System.out.println("QQ号不能以0开头!"); } } else { System.out.println("QQ号超度不符合要求!"); } } }
本文出自 “司马囧” 博客,谢绝转载!
原文:http://9274590.blog.51cto.com/9264590/1709716