我想知道是否有办法使用Javascript获取以下表格的电话号码的正则表达式:
0610101010 => 10 digits that starts with 06 or 05.
+212565656566 => (+) followed by 212 then another 9 digits.
谢谢。
答案 0 :(得分:1)
尝试这样的事情:
/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
答案 1 :(得分:1)
这应该有效:
/^(0(6|5)\d{8}|\+212\d{9})$/