特定电话号码正则表达式

Specific Phone number regex

本文关键字:正则表达式 电话号码      更新时间:2023-09-26

我想知道是否有一种方法可以使用Javascript为电话号码提供正则表达式:

0610101010 => 10 digits that starts with 06 or 05.
+212565656566 => (+) followed by 212 then another 9 digits. 

谢谢。

这应该有效:

/^(0(6|5)'d{8}|'+212'd{9})$/

尝试这样的事情:

/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