java验证电话号码的正则_java使用正则表达式判断电话号码

java验证电话号码的正则_java使用正则表达式判断电话号码Iwanttohavephonenumberinworkingcombinationof’0’followedby10digitmobilenumber(or)0091folllowedby10digitmobilenumber(or)+91followedby10digitnumber.1)0followedand+91fo…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

java验证电话号码的正则_java使用正则表达式判断电话号码

I want to have phone number in working combination of ‘0’ followed by 10 digit mobile number (or) 0091 folllowed by 10 digit mobile number (or) +91 followed by 10 digit number.

1) 0 followed and +91 folowed numbers are working with following regex i also want 0091 followed number to be worked, my regex is:

“^([0]|(?:[0][0]|\\+)(91))([7-9]{1})([0-9]{9})$”;

Could you suggest me working a regex.

解决方案

The exact regex you seem to be going for (based on what you’ve tried so far) is:

^(?:0091|\\+91|0)[7-9][0-9]{9}$

Begins with 0, +91 or 0091

Followed by a 7-9

Followed by exactly 9 numbers

No capture groups

Must match entire input

As a general tip, to have worked this out yourself I’d advise using a site like RegExr or RegexPal

Set it to multi-line mode (so that ^ and $ match at the end of each line) then add 0091, +91 and 0 into the input box on separate lines – so you have something like this.

Then try to make a regex that matches just that part, in your case you needed something like

^0091|\+91|0$

Note: on RegExr you don’t have to escape backslashes (so when you use the regex in java you need to go through escaping them).

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/192596.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • github上开源的优秀android项目

    github上开源的优秀android项目源码大招:不服来战!撸这些完整项目,你不牛逼都难!经常有人问我有没有什么项目代码,我回复说去Github找,但是还是好多人不知道如何找到那些比较好的项目。今天花了点时间找了些安卓的项目,觉得还是不错的,几乎就是自己生活常用的一些app,如果你是一个Android开发者,我觉得撸完这些项目,你想不牛逼都难。菜鸟新闻菜鸟新闻客户端是一个仿照36Kr官方,实时抓取36Kr…

    2022年6月16日
    34
  • C/C++中static变量和static函数的用法

    C/C++中static变量和static函数的用法静态成员数据和静态成员函数1.C中静态数据和静态函数的用法C语言中定义一个静态变量和静态函数主要是为了满足某个文件的需求比如我们在文件List.c中定义staticintcount=0;//静态变量staticintget_last_node(List*Head)

    2022年7月16日
    125
  • mysql 查看函数fsync_sync/fsync/fdatasync的简单比较

    mysql 查看函数fsync_sync/fsync/fdatasync的简单比较此文主要转载自官网上有关于MySQL的flushmethod的设置参数说明,但可能很多人不太明白。下文就详细说明此问题。首先官网的说明如下:http://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html#sysvar_innodb_flush_methodinnodb_flush_methodCommand-LineFormat–i…

    2022年5月31日
    32
  • 异或和与运算_逻辑异或运算规则

    异或和与运算_逻辑异或运算规则异或,是一个数学运算符,英文为exclusiveOR,缩写为xor,应用于逻辑运算。异或的数学符号为“⊕”,计算机符号为“xor”。其运算法则为:a⊕b=(¬a∧b)∨(a

    2022年8月1日
    3
  • enableEventValidation

    enableEventValidation回发或回调参数无效。在配置中使用或在页面中使用启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用ClientS

    2022年7月4日
    25
  • navicat最新激活码【2021最新】

    (navicat最新激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/ide…

    2022年3月22日
    143

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号