js验证函数

来源:互联网 发布:pdf解密软件下载 编辑:程序博客网 时间:2024/05/08 16:54
<script language="JavaScript" type="text/javascript">
function submitUpdateInfo(){
    if(document.getElementById("username").value==""){
        window.alert("昵称不能为空");
        form1.username.focus();
        return false;
    }
    if(document.getElementById("username").value.length<2||document.getElementById("username").value.length>20){
        window.alert("请正确输入昵称");
        form1.username.focus();
        return false;
    }
    //-------------  身份证要是15位的数字,或18位的数字,17位的数字加上最后一位的字符x.
    //身份证不为空
    nationCard = document.getElementById("nationid").value;
    if(nationCard.length!=15 && nationCard.length!=18){
        alert("请正确输入15或18位的身份证号码!");
        form1.nationid.focus();
        form1.nationid.select();
        return false;
    }
    if (nationCard==""||nationCard.length==0){
        window.alert("身份证号码不能空");
        form1.nationid.focus();
        return false;
    }
    //身份证的格式
    if(nationCard.length==15 ){
        if (isNaN(nationCard)){
            window.alert("15位身份证的输入有误,请正确输入!");
            form1.nationid.focus();
            form1.nationid.select();
            return false;
        }
    }
    
    if (nationCard.length==18){
        subStr = nationCard.substring(0,17);
        lastChar = nationCard.substring(17);
        if (isNaN(subStr)){
            window.alert("18位身份证输入有误,请正确输入!");
            form1.nationid.focus();
            form1.nationid.select();
            return false;
        }else if (isNaN(lastChar)){
            if(lastChar!="X" && lastChar!="x"){
                window.alert("18位的身份证号码最后一位有误!");
                form1.nationid.focus();
                form1.nationid.select();
                return false;
            }
        }
    }
    /////---------------------------------身份证检查结束
    if(document.getElementById("email").value==""){
        window.alert("电子邮件格式错误");
        form1.safeemail.focus();
        return false;
    }
    if(document.getElementById("email").value.indexOf('@')==-1||document.getElementById("email").value.indexOf('.')==-1){
        window.alert("电子邮件格式错误");
        form1.safeemail.focus();
        return false;
    }
    if(document.getElementById("city").value==""){
        window.alert("城市不为空");
        form1.city.focus();
        return false;
    }
    document.form1.submit();
}
function resetUpdateInfo(){
    document.form1.reset();
}
    
function  prePic (visualize){
    if (visualize=="myVisualize")
        document.getElementById("myVisualizeArea").innerHTML="<img src="+document.form1.myVisualize.value+" width=89 height=67 alt=我的形象>";
    if (visualize=="personalVisualize")
        document.getElementById("personalVisualizeArea").innerHTML="<img src="+document.form1.personalVisualize.value+" width=89 height=67 alt=我的个性形象>";
}
//设置原来性别的选中状态
document.form1.sex[<%=sexValue%>].checked =true;
</script>
原创粉丝点击