正则表达式xxxx.xxx.xxx

Sve*_*ven 3 javascript regex asp.net

我需要验证增值税号码.

xxxx.xxx.xxx - > 0123.456.789是有效数字.

我发现了一个正则表达式

^(BE)[0-1]{1}[0-9]{9}$|^((BE)|(BE ))[0-1]{1}(\d{3})([.]{1})(\d{3})([.]{1})(\d{3})
Run Code Online (Sandbox Code Playgroud)

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

但我需要的是只验证xxxx.xxx.xxx(没有别的是有效的,只有这个)

所以4位数,一个点,3位数,一个点,3位数.

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

man*_*lds 6

这应该工作:

^[01]\d{3}\.\d{3}\.\d{3}$
Run Code Online (Sandbox Code Playgroud)


Ode*_*ded 5

干得好:

^[01]\d{3}\.\d{3}\.\d{3}$
Run Code Online (Sandbox Code Playgroud)

分解:

^      - 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
Run Code Online (Sandbox Code Playgroud)

  • 这个问题是血浴 (3认同)
  • @Abe哈哈完全同意 (2认同)