/^\(?([1-9]{1,3})\)??([0-9]{9})$/
这是用于验证号码。 我是正则表达式的新手。你能解释一下它的作用吗?
答案 0 :(得分:2)
简单来说,我只是上传这张图片(来自http://www.regexper.com/#%2F%5E%5C(%3F(%5B1-9%5D%7B1%2C3%7D)%5C)%3F%3F(%5B0-9%5D%7B9%7D)%24%2F)
答案 1 :(得分:2)
/
^ <-- beginning of line
\(? <-- optional "("
([1-9]{1,3}) <-- 1, 2, or 3 digits (each between 1 and 9)
\)?? <-- optional ")" (matches the first close parenthesis if multiple are present in the string)
([0-9]{9}) <-- 9 digits (each between 0 and 9)
$ <-- end of line
/
它似乎匹配以区域/国家/地区代码为前缀的电话号码
答案 2 :(得分:2)
请参阅此自由间距模式。我假设你正在使用PCRE
/^ #match the beginning of the string
\(? #match literal (, if exists
( #group 1
[1-9]{1,3} #match one, two, or three digit(s). The digit must be between 1-9
) #end of group1
\)?? #match literal ), if exists
( #group 2
[0-9]{9} #match 9 digits, 0-9
) #end of group2
$/ #match the end of the string