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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 又一个新的开始「建议收藏」

    又有一段时间没有进行整理和总结输出了,其实最近也没有闲着,也是一直在看书学习状态,看Java并发编程相关的知识,之前买了《Java并发编程的艺术》,去年看了一遍。最近又买了《Java并发编程实战》,两本书都挺好的,《Java并发编程的艺术》这本看了一遍,最近在看其中的一些章节,又有新的一些体会,新的认识。很多时候看了一遍的书,就不会在读第二遍,但是有些书适合读两遍以上,要不然根本无法理解书中的精…

    2022年2月27日
    41
  • QImage和QPixmap相互转换

    QImage和QPixmap相互转换QPainterp this QPixmappixma pixmap load image 路飞 jpg QPixmap gt QImageQImage pixmap toImage p drawImage 0 0 tempImage QImageimage

    2025年6月29日
    1
  • windows远程桌面和teamviewer_windows远程桌面端口

    windows远程桌面和teamviewer_windows远程桌面端口Windows的远程桌面输错了一次密码,然后就怎么都连接不上了,查了半天发现傻缺360会默认屏蔽Windows的远程桌面和数据库连接…..大家没事都卸载了360吧转载于:https://www.cnblogs.com/JiangOil/p/10561828.html…

    2025年11月19日
    5
  • java吧_死磕好不好

    java吧_死磕好不好死磕Java——CAS

    2022年4月22日
    48
  • codeforces 437C The Child and Toy

    codeforces 437C The Child and Toy

    2022年1月25日
    58
  • 一小时搞定简单VBA编程 Excel宏编程快速上手

    一小时搞定简单VBA编程 Excel宏编程快速上手Excel宏编程可以快速完成批量表格操作:复制粘贴、数据过滤等,宏代码基于VB语言实现,有基础的编程经验就能快速阅读。下面是我的学习笔记。1.ExcelVBA编辑界面(进入路径:sheet名称–>鼠标右键菜单–>查看代码)2.输入代码方法:在VBE编辑器的代码模块中输入VBA代码,通常有以下几种方法:■手工键盘输入;■使用宏录制器,即选择菜单“工具—…

    2022年6月6日
    46

发表回复

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

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