Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

正则实现匹配区号,但是不要有400

可以让用户输入区号,如028-556321 但是不让用户输入400开头的电话号码,正则咋写啊?

我使用了/^[^(400)]\d{2,4}-\d{3,5}/这种,但是开头的 [^(400)] 其实就相当于 [^400]也就是4和0都不能作为开头,不是匹配的 400,所以想问下要咋做啊。

注: 这里的 d 显示的时候会显示成 \d ,大家忽略哈。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
/^(?!400)d{2,4}-d{3,5}/

这里有个问题就是400x-12345这种也不能匹配


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...