首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xxxx.xxx.xxx的正则表达式

xxxx.xxx.xxx的正则表达式
EN

Stack Overflow用户
提问于 2011-05-05 04:15:37
回答 7查看 8.6K关注 0票数 3

我需要验证增值税号码。

xxxx.xxx.xxx --> 0123.456.789是一个有效的数字。

我发现了一个正则表达式

代码语言:javascript
复制
^(BE)[0-1]{1}[0-9]{9}$|^((BE)|(BE ))[0-1]{1}(\d{3})([.]{1})(\d{3})([.]{1})(\d{3})

这将验证以下条目: BE 0123.456.789。

但是我需要的是只验证xxxx.xxx.xxx (其他的都是有效的,只有这个)

所以4个数字,一个点,3个数字,一个点,3个数字。

它还需要从0或1开始(第一个x --> 0或1)

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2011-05-05 04:18:54

这应该是可行的:

代码语言:javascript
复制
^[01]\d{3}\.\d{3}\.\d{3}$
票数 6
EN

Stack Overflow用户

发布于 2011-05-05 04:17:52

这就是了:

代码语言:javascript
复制
^[01]\d{3}\.\d{3}\.\d{3}$

细目:

代码语言:javascript
复制
^      - Start of string
[01]   - Followed by a 0 or 1
\d{3}  - Followed by three numerals
\.     - Followed by a .
\d{3}  - Followed by three numerals
\.     - Followed by a .
\d{3}  - Followed by three numerals
$      - Followed by end of string
票数 8
EN

Stack Overflow用户

发布于 2011-05-05 04:17:36

这是表达式

代码语言:javascript
复制
^[0-1]\d{3}[.]\d{3}[.]\d{3}$

^     // start of the input
\d{#} // numbers repeated # times
[.]   // literal . (same as  \.  )
$     // end of the input
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5889310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档