<script language="JavaScript">
<!--
function CheckScript(theForm)
{
  if(theForm.loginname.value.length > 50){
       alert("会员登录名不能大于50个字符,请重新输入!");
       theForm.loginname.select();
       theForm.loginname.focus();
       return (false);
       }
}
//-->
</script>

解决方案 »

  1.   

    <input type="text" name="t1" onblur="if(this.value.length>=50){alert('x>50')"}
      

  2.   

    这种判断方法不适用于中文。
    javascript将中文字符算作一个字符,所以如果输入50个中文,他不会判断出错,但实际上已经是100个字符了。
      

  3.   

    <input name="test">
    <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
    <!--
    function strLen(txtstr){
        return txtstr.replace(/[^\x00-\xff]/g,"xx").length;
    }
    test.value=strLen("gq事业a业")
    //-->
    </SCRIPT>
      

  4.   

    <input type="text" style='width:800'name="t1" maxlength=60 onblur="if(calLen(this.value)>=50){alert('x>50')}">
    <script>
    function calLen(strText)
    {
    var nLen = 0;
    for(var i = 0; i < strText.length;i++)
    {
    if(strText.charCodeAt(i) > 128) 
    nLen = nLen + 2;
    else 
    nLen++
    }
    return nLen;
    }
    </script>
      

  5.   

    /*** 返回字节数 ***/
    String.prototype.lenb = function() {
      return this.replace(/[^\x00-\xff]/g,"**").length;
    }