正则表达式“所有数字对手机号码不应该相同” [英] Regex for "All the digits should not be same for a mobile number"

查看:185
本文介绍了正则表达式“所有数字对手机号码不应该相同”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我是新来的正则表达式。我需要一个10位手机号码的正则表达式,它不应该以0或1开头,并且所有10位数字都不能重复相同的号码。
抱歉缺少信息。请帮助解决这个问题。



请找到html代码。

 < div class =col-md-2> 
< label>手机< / label>
< input id =type =textui-mask =(999)999-9999name =mobilePhone
class =form-control
ng- model =patientIn.addressList [0] .phoneNumbers ['mobile']
ng-change =setPhoneNumber('mobile')
ui-mask-placeholder-char =space
model-view-value =true/>
< p ng-show =(frmPatientEdit。$ submitted&& frmPatientEdit.mobilePhone。$ invalid)||(frmPatientEdit.mobilePhone。$ invalid&& frmPatientEdit.mobilePhone。$ touched)
class =error>手机无效。< / p>


解决方案

在您的情况下,手机号码格式为9999)999-9999
因此,正则表达式应该是

  / \((\ d)\ 1 {3} \)\1 {3} -\1 {4} /。test((9999)999-9999)
true

/ \\ \\((\ d)\ 1 {3} \)\ 1 {3} -\1 {4} /。test((9999)929-9999)
false

这里,正则表达式的分解解释是

\( - >匹配(在您的字符串中)

( \ d) - >匹配第一个整数并捕获它(以便我们稍后可以反向引用它)



\ 1 - >选取第一个捕获的元素

{3} - >检查捕获是否重复3次

(空格) - >空格



\1 {3} - >检查捕获是否重复3次(反向引用)

- - >检查hiphen



\1 {4} - >检查捕获是否重复4次

Editted: I am new to regular expressions. I need a regex for a 10-digit mobile number which should not start with 0 or 1 and the same number cannot be repeated for all 10 digits. Sorry for the lack of information. Please help for this problem.

Please find the html code.

  <div class="col-md-2">
                                    <label>Mobile Phone</label>
                                    <input id="" type="text" ui-mask="(999) 999-9999" name="mobilePhone"
                                           class="form-control"
                                           ng-model="patientIn.addressList[0].phoneNumbers['mobile']"
                                           ng-change="setPhoneNumber('mobile')"
                                           ui-mask-placeholder-char="space"
                                           model-view-value="true"/>
                                    <p ng-show="(frmPatientEdit.$submitted && frmPatientEdit.mobilePhone.$invalid) || (frmPatientEdit.mobilePhone.$invalid && frmPatientEdit.mobilePhone.$touched)"
                                       class="error">Mobile Phone is Invalid.</p>

解决方案

In your case, the mobile number is of format (9999) 999-9999 Hence , the regex should be

/\((\d)\1{3}\) \1{3}-\1{4}/.test("(9999) 999-9999")
"true"

/\((\d)\1{3}\) \1{3}-\1{4}/.test("(9999) 929-9999")
"false"

here, the split-up explanation of the regex is

\( -> matches the ( in your string

(\d) -> matches the first integer and capture it (so that we could backreference it later)

\1 -> picks the first captured element

{3} -> checks if the capture is repeating 3 times

(space) -> space

\1{3} -> checks if the capture is repeating 3 times(backreferencing)

- -> checks for hiphen

\1{4} -> checks if the capture is repeating 4 times

这篇关于正则表达式“所有数字对手机号码不应该相同”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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