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

    登录验证:
    $(function(){
    $("#文本框id").focus(function(){ // 输入账号的文本框获得鼠标焦点
    var name = $(this).val(); // 得到当前文本框的值
    if(name=="请输入6~12位账号"){
    $(this).val(""); // 如果符合条件,则清空文本框内容
    }
    });
    $("#文本框id").blur(function(){// 文本框失去鼠标焦点
    var name = $(this).val(); // 得到当前文本框的值
    if(name==""){
    $(this).val("请输入6~12位账号");// 如果符合条件,则设置内容
    }
    });
    });
    表单验证:
    $(function(){
    $("#txtNo").blur(function(){
    var name=$(this).val();
    if(name==""||name==null)
    {
    $("#prompt_no").html("用户账号不能为空!");
    return false;
    }
    if(name.length<6||name.length>12)
    {
    $("#prompt_no").html("账号的长度在6到12位之间!");
    return false;
    }
    $("#prompt_no").html("<img src='images/ok.gif'/>");
    });
    $("#txtPwd").blur(function(){
    var pwd=$(this).val()
    if(pwd==""||pwd==null)
    {
    $("#prompt_pwd").html("密码不能为空!");
    return false;
    }
    if(pwd.length<6||pwd.length>12)
    {
    $("#prompt_pwd").html("密码的长度在6到12位之间");
    return false;
    }
    $("#prompt_pwd").html("<img src='images/ok.gif'/>");
    });
    $("#txtConfirmPwd").blur(function(){
    var pwds=$(this).val();
    if(pwds==""||pwds==null){
    $("#prompt_confirmpwd").html("密码不能为空!");
    return false;
    }
    if(pwds!=$("#txtPwd").val())
    {
    $("#prompt_confirmpwd").html("两次输入的密码要一致!");
    return false;
    }
    $("#prompt_confirmpwd").html("<img src='images/ok.gif'/>");
    });

    $("#txtName").blur(function(){
    var names=$(this).val();
    if(names==""||names==null){
    $("#prompt_name").html("用户名不能为空!");
    return false;
    }
    if(names.length<6||names.length>12)
    {
    $("#prompt_name").html("用户名的长度在6到12位之间!");
    return false;
    }
    $("#prompt_name").html("<img src='images/ok.gif'/>");

    });
    $("#txtId").blur(function(){
    var idReg=/^d{15}$|^d{18}$/;
    var id=$(this).val();
    if(id==""||id==null)
    {
    $("#prompt_id").html("身份证不能为空!");
    return false;
    }
    if(!idReg.test(id))
    {
    $("#prompt_id").html("身份证格式不正确!");
    return false;
    }
    $("#prompt_no").html("<img src='images/ok.gif'/>");
    });

    $("#txtPhone").blur(function(){
    var phoneReg=/^(13|15|18)d{9}$/;
    var phone=$(this).val();
    if(phone==""||phone==null)
    {
    $("#prompt_phone").html("手机号不能为空!");
    return false;
    }
    if(!phoneReg.test(phone))
    {
    $("#prompt_phone").html("手机号格式不正确!");
    return false;
    }
    $("#prompt_phone").html("<img src='images/ok.gif'/>");
    });

  • 相关阅读:
    Objective-C Loops
    HDU 4757 Tree(可持久化Trie+Tarjan离线LCA)
    Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(可持久化Trie)
    HDU 5416 CRB and Tree(前缀思想+DFS)
    HDU 3695 Computer Virus on Planet Pandora(AC自动机模版题)
    HDU 2222 Keywords Search(AC自动机模版题)
    POJ 2697 A Board Game(Trie判重+BFS)
    HDU 4287 Intelligent IME(字典树数组版)
    HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
    HDU 1565&1569 方格取数系列(状压DP或者最大流)
  • 原文地址:https://www.cnblogs.com/you-zi/p/4351200.html
Copyright © 2011-2022 走看看