Home > Web Front-end > JS Tutorial > body text

Regular expression to verify whether the QQ number is entered correctly

php中世界最好的语言
Release: 2018-03-29 15:11:28
Original
5858 people have browsed it

这次给大家带来正则表达式验证qq号码是否输入正确,正则表达式验证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号错误"); 
  } 
}
Copy after login

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

js中的正则表达式如何使用(附代码)

用正则验证用户的帐号密码以及手机号码与身份证的方法

The above is the detailed content of Regular expression to verify whether the QQ number is entered correctly. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template