简单的电话正则表达式
我想要一个正则表达式来检查以下内容:
- 字符串以 + 开头
- 在“+”之后只能出现数字
- 在 + 之后应该至少有 4 个数字
有谁知道如何做到这一点?
I want a regex that checks the following things:
- The string starts with an +
- After the '+' only numbers can occur
- There should be atleast 4 numbers after the +
Does anyone know how to make this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将满足您的要求。
^
是字符串开始的锚点\d
是一个数字{4,}
表示前面表达式中的至少 4 个(这里是<代码>\d)。如果需要,您可以添加最大值,例如{4,20}
允许至少 4 个字符,最多 20 个字符。$
是字符串结尾的锚点will meet your requirements.
^
is the anchor for start fo the string\d
is a digit{4,}
says at least 4 of the preceding expression (here the\d
). you can add a maximum if needed like{4,20}
would allow at least 4 and at most 20 characters.$
is the anchor for the end of the string比您的要求更笼统,但您可以将其专门化。说明:
国际代码由 00 或 + 和 2 或 3 位数字组成。根据您的需要修改表达式。
国际代码是可选的 - 如果需要
数字,请将其删除:最少 4 位,最多 14 位。根据您的需要更改值。
问候
一个。
More general than your request, but you can specialize it. Explaining:
international code with 00 or + and 2 or 3 digits. Modify the expression according to your needs.
international code is optional - remove it if it is required
digits: minimum 4, maximum 14. Change the values according to your needs.
Regards
A.
如果 15 是最大数字限制
,或者按照 Stema 建议将第二个参数保留为空,这应该会有所帮助。
This should help if 15 is the atmost limit of numbers
OR rather keep the second parameter blank as stema suggested.
我选择了这个:
I went with this one: