求一段控制输入字数的PHP或JS语句

请赐教:求一段控制输入字数的PHP或JS语句,如:发表一个贴子,标题限制为4-20个汉字,内容10-5000个汉字?

无聊分子给的代码,用strlen就可以统计字数了~~

<?PHP

//...密码..略......

if (4<=strlen($bt)<=20) {
die('标题数目不对~~4-20'); //也可以用echo
}
if (10<=strlen($nr)<=3000) {
die('内容数目不对~~10-3000');
}

//.......其他处理..又略...

?>

无聊分子问你一句:你是不是想做论坛?
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-02-13
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>资料填写</title>
</head>

<body>

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="313">
<tr>
<td width="100%" height="28">
<p align="center"><b>第二步:输入您公司的资料<font color=red><%=price%></font></b></td>
</tr>
<tr>
<td width="100%" height="281" valign="middle">
<form method="POST" action="upload.asp" onsubmit="return input()">
<p align="left">公司名称:<input type="text" name="name" size="20"></p>
<p align="left">公司地址:<input type="text" name="address" size="20"></p>
<p align="left">公司电话:<input type="text" name="tel" size="20"></p>
<p align="left">公司网址:<input type="text" name="www" size="20"></p>
<p align="left">公司图片:<input type=file name="img" size="20"></p>
<p><input type="submit" name="submit" value="确定" >

<script language="JavaScript">
<!--
function input()
{var M1=document.all.name.value;
if(M1.length>20)
{alert("输入的字符不能超过20个字符");
document.all.name.focus();
return false;}
if (M1=="")
{alert("内容不可以为空.");
document.all.name.focus();
return false;
}
else
return true;
}
//-->
</script>

</form>
</td>
</tr>
</table>

</body>

</html>