<script language="javascript">
//判断中英文:
function isChinese(str)
{
var lst = /[u00-uFF]/;
return !lst.test(str);
}
if(isChinese("名字"))
alert("Yes");
else
alert("NO");
</script>
________________________________________________
<script language="javascript">
function isChinese(str)
{
var lst = /[u00-uFF]/;
return !lst.test(str);
}
function strlen(str)
{
var strlength=0;
for (i=0;i<str.length;i++)
{
if (isChinese(str.charAt(i))==true)
strlength=strlength + 2;
else
strlength=strlength + 1;
}
return strlength;
}
//-------------------
var strtest="This测试!";
alert(strlen(strtest));
</script>
_________________________________________________
/
_________________________________________________
不分中英文字符都按一个字符计算:
<td>
<textarea name="content" cols=60 rows=8 onKeyUp="textLimitCheck(this,70);"></textarea>
<br>限 70 个字符 已输入 <font color="#CC0000"><span id="messageCount">0</span></font> 个字
</td>
<script>
function textLimitCheck(thisArea, maxLength){
if (thisArea.value.length > maxLength)
{
alert(maxLength + ' 个字限制. \r超出的将自动去除.');
thisArea.value = thisArea.value.substring(0, maxLength);
thisArea.focus();
}
/*回写span的值,当前填写文字的数量*/
messageCount.innerText = thisArea.value.length;
}
</script>