zoukankan      html  css  js  c++  java
  • 表单验证

    1.    function mysubmit(){  
    2.                if(check()){  
    3.                    alert("mainok");  
    4.                    document.getElementById("form1").submit();  
    5.                }  
    6.            }  
    7.            function check(){  
    8.                var username=document.getElementById("username").value;  
    9.                var password=document.getElementById("password").value;  
    10.                var repassword=document.getElementById("repassword").value;  
    11.                var email=document.getElementById("email").value;  
    12.                var mobile=document.getElementById("mobile").value;  
    13.                var birthday=document.getElementById("birthday").value;  
    14.                if(username==null||username==""){  
    15.                    alert("用户名不能为空");  
    16.                    document.getElementById("username").focus();  
    17.                    return false;  
    18.                }  
    19.                if(username.length<5){  
    20.                    alert("用户名长度为5-20个字符");  
    21.                    document.getElementById("username").focus();  
    22.                    return false;  
    23.                }  
    24.                if(password==null||password==""){  
    25.                    alert("密码不能为空");  
    26.                    document.getElementById("password").focus();  
    27.                    return false;  
    28.                }  
    29.                if(password.length<6||password.length>20){  
    30.                    alert("密码长度为6-20个字符");  
    31.                    document.getElementById("password").focus();  
    32.                    return false;  
    33.                }  
    34.                if(password!=repassword){  
    35.                    alert("密码不一致");  
    36.                    document.getElementById("password").focus();  
    37.                    return false;  
    38.                }  
    39.                if(email==null||email==""){  
    40.                    alert("邮箱不能为空");  
    41.                    document.getElementById("email").focus();  
    42.                    return false;  
    43.                }  
    44.                if(email.indexOf("@")==-1){  
    45.                    alert("邮箱格式错误");  
    46.                    document.getElementById("email").focus();  
    47.                    return false;  
    48.                }  
    49.                var str=/^1[3|4|5|8][0-9]d{8}$/;  
    50.                if(mobile!=null&&mobile!=""){  
    51.                    if(!str.test(mobile)){  
    52.                        alert("手机格式错误");  
    53.                        document.getElementById("mobile").focus();  
    54.                        return false;  
    55.                    }  
    56.                }  
    57.                  
    58.                return true;  
    59.            }  
    60.            function checkname(){  
    61.                var username=document.getElementById("username").value;  
    62.                $.ajax({  
    63.                    type:"post",  
    64.                    url:"checkname",  
    65.                    data:{  
    66.                        username:username  
    67.                    },  
    68.                    success:function(data){  
    69.                        //alert(data);  
    70.                        if(data=="true"){  
    71.                            document.getElementById("username").focus();  
    72.                            alert("用户存在");  
    73.                            return false;  
    74.                        }  
    75.                    }  
    76.                })  
    77.            }  
  • 相关阅读:
    文件上传按钮样式定制
    消除2个按钮之间1px细节引起的冲突
    css 实用代码汇总
    除掉inline-block 间距
    SQL Server 创建索引的 5 种方法
    百度API从经纬度坐标到地址的转换服务
    百度地图API简单应用——1.根据地址查询经纬度
    极光API推送 (v3 版本)
    简单快捷地测试 JPush API
    使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
  • 原文地址:https://www.cnblogs.com/xiaobaizitaibai/p/8612651.html
Copyright © 2011-2022 走看看