简单的电话正则表达式

发布于 2024-11-16 00:50:27 字数 126 浏览 5 评论 0原文

我想要一个正则表达式来检查以下内容:

  1. 字符串以 + 开头
  2. 在“+”之后只能出现数字
  3. 在 + 之后应该至少有 4 个数字

有谁知道如何做到这一点?

I want a regex that checks the following things:

  1. The string starts with an +
  2. After the '+' only numbers can occur
  3. There should be atleast 4 numbers after the +

Does anyone know how to make this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一身软味 2024-11-23 00:50:27
/^+\d{4,}$/

将满足您的要求。

^ 是字符串开始的锚点

\d 是一个数字

{4,} 表示前面表达式中的至少 4 个(这里是<代码>\d)。如果需要,您可以添加最大值,例如 {4,20} 允许至少 4 个字符,最多 20 个字符。

$ 是字符串结尾的锚点

/^+\d{4,}$/

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

爱格式化 2024-11-23 00:50:27
/^((00|\+)[0-9]{2,3}){0,1}[0-9]{4,14}$/

比您的要求更笼统,但您可以将其专门化。说明:

((00|\+)[0-9]{2,3}) 

国际代码由 00 或 + 和 2 或 3 位数字组成。根据您的需要修改表达式。

 {0,1} 

国际代码是可选的 - 如果需要

[0-9]{4,14} 

数字,请将其删除:最少 4 位,最多 14 位。根据您的需要更改值。

问候
一个。

/^((00|\+)[0-9]{2,3}){0,1}[0-9]{4,14}$/

More general than your request, but you can specialize it. Explaining:

((00|\+)[0-9]{2,3}) 

international code with 00 or + and 2 or 3 digits. Modify the expression according to your needs.

 {0,1} 

international code is optional - remove it if it is required

[0-9]{4,14} 

digits: minimum 4, maximum 14. Change the values according to your needs.

Regards
A.

深海夜未眠 2024-11-23 00:50:27
/\+\d{4,15}/

如果 15 是最大数字限制

,或者按照 Stema 建议将第二个参数保留为空,这应该会有所帮助。

/\+\d{4,15}/

This should help if 15 is the atmost limit of numbers

OR rather keep the second parameter blank as stema suggested.

倒数 2024-11-23 00:50:27

我选择了这个:

/\A(([+]\d{3,})?\d{6,8})/

I went with this one:

/\A(([+]\d{3,})?\d{6,8})/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文