Javascript 特定电话号码regex
我想知道是否有一种方法可以让一个电话号码的正则表达式使用Javascript以以下形式出现:Javascript 特定电话号码regex,javascript,regex,Javascript,Regex,我想知道是否有一种方法可以让一个电话号码的正则表达式使用Javascript以以下形式出现: 0610101010 => 10 digits that starts with 06 or 05. +212565656566 => (+) followed by 212 then another 9 digits. 谢谢。试试这样: /0(5|6)[0-9]{8}|\+212[0-9]{9}/ 解释: / - The start of the regex 0 - Matche
0610101010 => 10 digits that starts with 06 or 05.
+212565656566 => (+) followed by 212 then another 9 digits.
谢谢。试试这样:
/0(5|6)[0-9]{8}|\+212[0-9]{9}/
解释:
/ - The start of the regex
0 - Matches a zero
(5|6) - Matches a five or six
[0-9]{8} - Matches eight characters in the range zero to nine
| - Second expression starts here
\+212 - Matches a plus followed by 212
[0-9]{9} - Matches nine characters in the range zero to nine
/ - End of regex
这应该起作用:
/^(0(6|5)\d{8}|\+212\d{9})$/
有。这些都是非常简单的规则,你可以很容易地在谷歌上搜索每一条规则。没问题,很高兴我能帮上忙。