正则表达式在Java手机号码验证 [英] regex for mobile number validation in java

查看:586
本文介绍了正则表达式在Java手机号码验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在工作中0的组合后的10位手机号码(或)0091 10位数的手机号码(或)folllowed +91其次是10位数字的电话号码。

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遵循和+91 folowed号码与正则表达式如下工作我也想跟着0091号进行的工作,我的正则表达式是:

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}$


  • 0,+91或0091
  • 开始
  • 其次是7-9

  • 后紧跟9个号码

  • 无捕获组

  • 必须匹配整个输入

  • 工作RegExr 例如

    作为一般的提示,已经制定了这一点,你自己我建议使用像 RegExr RegexPal

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

    将其设置为多行模式(让 ^ $ 比赛在每一行的结尾)再加入 0091 +91 0 到输入在单独的行盒 - 让您拥有这样的事情

    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$
    

    注意:在RegExr你没有逃跑反斜杠(所以当你在Java中使用正则表达式,你需要经过转义)

    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).

    这篇关于正则表达式在Java手机号码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆