【www.bbyears.com--正则表达式】
word-wrap: break-word; margin: 5px 0px; color: rgb(0, 0, 0); font-family: 'sans serif', tahoma, verdana, helvetica; font-size: 13.3333px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;">废话不多说了,直接给大家贴代码了,具体代码如下所示:
代码如下
package 正则表达式;
/*对QQ号码进行校验
要求5~15位,不能以0开头,只能是数字*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String qq ="23412312";
String regex ="[1-9][0-9]{4,14}";//第一位1-9之间的数字,第二位0-9之间的数字,数字范围4-14个之间
//String regex2 = "[1-9]\\d{4,14}";//此句也可以
boolean flag = qq.matches(regex);
if(flag)
System.out.println("QQ号正确");
else
System.out.println("QQ号错误");
}
}
以上所述是小编给大家介绍的正则表达式对qq号码进行校验,希望对大家有所帮助,在此也非常感谢大家对本网站的支持!
原文链接:http://blog.csdn.net/u012110719/article/details/40864759