解释这个正则表达式请var numbonly = / ^ [0-9] {3} \ d + $ /;

时间:2014-02-11 01:15:28

标签: javascript regex

var numbonly= /^[0-9]{3}\d+$/;

请告诉我这个正则表达式在JavaScript中意味着什么?我对这件事情很新,而且非常困难。

2 个答案:

答案 0 :(得分:2)

^ =字符串必须以

开头

[0-9] =任意数字0-9

{3} =必须有3位数

\d =任何数字([0-9]的缩写)

+ = +是{1,}的缩写。匹配一次或多次

$ =字符串结尾

所以在英语中,必须有一个数字[0-9],3次,然后另一个数字[0-9]必须存在1次或更多次。所以基本上这意味着4位或更多位数。所以它可以写得更短,就像这样....

^\d{4,}$

答案 1 :(得分:0)

^     Matches the beginning of the String 
[0-9] Matches characters in the range 0-9 
{3}   Matches the previous token [0-9] exactly 3 times 
\d    Matches any digit character
+     Matches previous token \d one or more times 
$     Matches the end of the String