解决方案 »

  1.   

    获得textarea 节点后.value.length获取长度试试 
      

  2.   

    关键是用户的输入内容要满足怎样的条件,其他的都是简单的判断
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style>
    .test{width:400px;height:30px;margin:100px auto;}
    input{padding:5px 0 5px 5px;float:left; width:198px;background:none;border:solid 1px #ccc;height:20px;}
    .test span{float:left;font-size:12px;height:30px;line-height:30px; padding-left:10px;}
    .awokeW{color:red;}
    .awokeR{color:green;}
    </style>
    <script>
    window.onload=function()
    {
    var oInput=document.getElementById('username');
    var oSpan=document.getElementById('awoke');
    oInput.onkeyup=function()
    {
    if(/^\w{6,10}$/g.test(this.value))
    {
    oSpan.className='awokeR';
    oSpan.innerHTML='填写正确';
    }
    else
    {
    oSpan.className='awokeW';
    oSpan.innerHTML='请确保填写内容在6-10个字符';
    }
    }
    }
    </script>
    </head><body>
    <div class="test">
    <input type="text" id="username" name="username" />
        <span class="awokeW" id="awoke"></span>
    </div>
    </body>
    </html>
      

  3.   

    个人觉得在失去焦点的时候进行判断比较好,可以用onblur()事件
      

  4.   

    var re=/[\u4e00-\u9fa5]/g;
    alert(!re.test('中文') ? 'Y' : 'N');
    alert(!re.test('中文2x') ? 'Y' : 'N');