2014-02-10 270 views
-1

我想RegExp与许多条件检查字符串匹配正则表达式

  1. 字符串长度必须为7
  2. 前两个数字必须是数字。
  3. 第三位数字必须是E
  4. 第四和第五位必须是数字,不能大于12
  5. 第六和第七位必须是数字

enter image description here

回答

4

请尝试:

var re = /^[0-9]{2}E(0[0-9]|1[0-2])[0-9]{2}$/; 

if (re.test(yourstring)) 
    // match 
else 
    // not match