不难, 判断麻烦死了...<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ *//* ]]> */
</style>
<script type="text/javascript">
//<![CDATA[
function fCkNum(o){
var limit=65534;
var err='输入错误, 请重新输入'
if(o.value!=null) {
var temp=temp1=temp2='';
var str=o.value+=''
try{
temp=str.match(/([\d]+?)\-[\d]+?\;[\d]+/)[1]+''
temp1=str.match(/[\d]+?\-([\d]+?)\;[\d]+/)[1]+''
temp2=str.match(/[\d]+?\-[\d]+?\;([\d]+)/)[1]+''
} catch(e) { o.value=''; alert(err);return false}
temp-=0; temp1-=0; temp2-=0;
if(temp>limit||temp1>limit||temp2>limit||temp>temp1){
alert(err); o.value=''; return false;
} else {
o.value=temp+'-'+temp1+';'+temp2;
alert('输入正确')
}
}
}
//]]>
</script>
</head>
<body>
<input type="text" onchange="fCkNum(this)" />
<xmp>检验文本框内的字符串符合 8080-8084;80 的形式
即 a-b;c;e-f;g
要求:
1 a,b,c 是小于65534的数字
2 a,b用-号 隔开,表示一个数字段,a<b
3 a-b和c用分号隔开刚刚开始学正则,一头雾水,看到一堆符号就晕,请高手指教!!!</xmp>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ *//* ]]> */
</style>
<script type="text/javascript">
//<![CDATA[
function fCkNum(o){
var limit=65534;
var err='输入错误, 请重新输入'
if(o.value!=null) {
var temp=temp1=temp2='';
var str=o.value+=''
try{
temp=str.match(/([\d]+?)\-[\d]+?\;[\d]+/)[1]+''
temp1=str.match(/[\d]+?\-([\d]+?)\;[\d]+/)[1]+''
temp2=str.match(/[\d]+?\-[\d]+?\;([\d]+)/)[1]+''
} catch(e) { o.value=''; alert(err);return false}
temp-=0; temp1-=0; temp2-=0;
if(temp>limit||temp1>limit||temp2>limit||temp>temp1){
alert(err); o.value=''; return false;
} else {
o.value=temp+'-'+temp1+';'+temp2;
alert('输入正确')
}
}
}
//]]>
</script>
</head>
<body>
<input type="text" onchange="fCkNum(this)" />
<xmp>检验文本框内的字符串符合 8080-8084;80 的形式
即 a-b;c;e-f;g
要求:
1 a,b,c 是小于65534的数字
2 a,b用-号 隔开,表示一个数字段,a<b
3 a-b和c用分号隔开刚刚开始学正则,一头雾水,看到一堆符号就晕,请高手指教!!!</xmp>
</body>
</html>
是我没说清楚……
a;b-c
或者只有a 只有b-c都应该是正确的
就是说a 和 b-c的任意组合 中间用分号 隔开汗~~~~
还有a-b;c-d;e
a-b;c;d-e 等任意组合
http://www.regexlab.com/zh/regref.htm
我瞅瞅
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>zhangli.test</title>
</head>
<script language="javascript">
function fCkNum(s){
var limit=65534;
var str = s.value;
var format1 = /((^|;)\d+(\-\d+)?)+$/;
var format2 = /\d+\-\d+/;
var flag1 = format1.test(str);
if(!flag1)
alert("wrong")
var field = str.split(";");
for(var i = 0; i < field.length; i++){
var flag2 = format2.test(field[i]);
if(flag2){
var temp = str.match(/([\d]+?)\-[\d]+?/)[1]+'';
var temp1 = str.match(/[\d]+?\-([\d]+?)/)[1]+'';
if(temp > limit || temp1 > limit | temp > temp1){
alert("wrong");}
}else{
if(field[i]>limit){
alert("wrong");}
}
}
}
</script>
<body>
<input type="text" onchange="fCkNum(this)" />
</body>
</html>谁能给介绍学习javascript的书,或者学习经验啊?