需求如下:
1. 匹配[!一定要求的字符串,数字,数字!]
2. 在 "[!!]"两边可有可无四则运算符,且可有可无 "()"
3. 在 "[!!]" 中间不能有连续的 "," 号
1. 匹配[!一定要求的字符串,数字,数字!]
2. 在 "[!!]"两边可有可无四则运算符,且可有可无 "()"
3. 在 "[!!]" 中间不能有连续的 "," 号
<SCRIPT type="text/javaScript">
<!--
// if match return true
//else return false;
function isMatch(str){
if(str.match(/^(^([\(\)]{0,}\[\![0-9a-zA-Z\_\-]{1,}\,\d{1}\,\d{1,}\!\][\)\(]{0,}[\+\-\*\/\%]{0,}){1,}
([\(\)]{0,}\[\![0-9a-zA-Z\_\-]{1,}\,\d{1,}\,\d{1,}\!\][\(\)]{0,}){1,}$)*$/g)
|| str.match(/^(\[\![0-9a-zA-Z\_\-]{1,}\,\d{1}\,\d{1,}\!\])$/g) ){
return true;
}
return false;
}
//the function of test
function test(inputStr) {
if(true == isMatch(inputStr)){
alert(1);
}else{
alert(0);
}
}
//-->
</SCRIPT>
<!--测试-->
<input type = "text" id = "test" onchange ="test(this.value)">