跪求大神帮写一段代码 reg.163.com 那里的注册页面里有个功能,比如我输入的注册邮箱格式不对的话,输入框会变成红色
希望大神写的代码就是拥有简单的判断功能就好了,比如判断输入是否数字,如果输入的不是数字的话,输入框会变成红色,最好能帮我写一个简单而完整的小网页,有一个输入框,然后能判断就好了。
本人初学,那注册页面的代码实在看不懂,希望有大神可以帮忙写一下,方便我学习,谢谢

解决方案 »

  1.   


    <!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>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script type="text/javascript">
            function aa(obj){
                var v=obj.value;
                if(isNaN(v)){
                    obj.style.borderColor="#ff0000";
                }else{
                    obj.style.borderColor="";
                }
            }
        </script>
      </head>
      <body>
          <input onkeyup="aa(this)" />
      </body>
    </html>
      

  2.   

    为什么我修改了一下你帮我写的代码,他就不行了?帮我看下吧
    function name(obj)                 // <input onkeyup="name(this)" />
    {
    var v=obj.value;
        if(/^[\x80-\xff]*$/(v))
    {
    obj.style.borderColor="#ff0000";
        }
    else
    {
            obj.style.borderColor="";
        }
    }
      

  3.   


    <!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>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script type="text/javascript">
            function aa(obj){
                var v=obj.value;
                if(v.match(/[^0-9]/)!=null){
                    obj.style.borderColor="#ff0000";
                }else{
                    obj.style.borderColor="";
                }
            }
        </script>
      </head>
      <body>
          <input onkeyup="aa(this)" />
      </body>
    </html>
      

  4.   

    上面的这段,如果输入数字以外的字符,边框就会变成红色。v.match()括号里面放正则表达式
    具体的你可以搜下“javascript 正则表达式”,这里面也有介绍http://www.w3school.com.cn/js/js_obj_regexp.asp