带有加号的电话号码验证可选 [英] Phone number validation with plus sign optional
本文介绍了带有加号的电话号码验证可选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何才能仅在开头和之后验证带有加号的可选电话号码?
How can i validate a phone number with plus sign optional only at the beginning and after that any number of digits with number only.
我尝试过:-
/^\+(?:[\d]*)$/
修改会如何
推荐答案
/^\+?(?:[\d]*)$/
问号表明加号可以存在或不存在.但是,您的表情可以进行很多优化:
The questionmark tells that the plus sign can be there or not. However, your expression can be optimized quite a bit:
/^\+?\d+$/
我将 *
更改为 +
,因为表达式只匹配加号. \ d *
建议应匹配0个或多个数字.
I changed the *
to a +
as the expression would match just a plus sign. \d*
suggests that it should match 0 or more digits.
这是 关于Regexr的演示 .
这篇关于带有加号的电话号码验证可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文