Home  >  Article  >  Web Front-end  >  Example of regular expression verification of QQ number

Example of regular expression verification of QQ number

零下一度
零下一度Original
2018-05-16 11:31:194302browse

这篇文章主要介绍了正则表达式对qq号码进行校验的相关知识,非常不错,具有参考借鉴价值,需要的的朋友参考下吧

废话不多说了,直接给大家贴代码了,具体代码如下所示:

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号错误"); 
  } 
}

The above is the detailed content of Example of regular expression verification of QQ number. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn