boodstrap 简单的 注册验证

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Using Ajax to submit data</title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd-part/dist/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd-part/dist/css/bootstrapValidator.css"/>

    <script type="text/javascript" src="${pageContext.request.contextPath}/3rd-part/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/3rd-part/dist/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/3rd-part/dist/js/bootstrapValidator.js"></script>
</head>
<body>

<div class="container">
    <h1 align="center" style="margin-top: 100px;font-weight: bold;margin-bottom: 40px;" >注册商城账号</h1>

     <!-- class都是bootstrap定义好的样式,验证是根据input中的name值 -->
     <form style="margin-left: 400px;" id="defaultForm" method="post" class="form-horizontal"  >
         
         <!-- 下面这个div必须要有,插件根据这个进行添加提示 -->
         <div  class="form-group" style="height: 60px;" >
             <div align="left" class="col-lg-5" style="width:380px;" >
                 <input type="text" class="form-control"
                 name="phone" placeholder="请输入手机号码"
                 style="height: 45px;"
                  />
             </div>
         </div>

         <div  class="form-group" style="height: 60px;" >
             <div align="left" class="col-lg-5" style="width:380px;" >
                 <input type="text" class="form-control"
                 name="mail" placeholder="请输入邮箱"
                 style="height: 45px;" />
             </div>
         </div>

         <div class="form-group" style="height: 60px;" >
             <div align="left" class="col-lg-5" style="width:380px;" >
                 <input type="password" class="form-control"
                 name="password" placeholder="请输入密码"
                 style="height: 45px;" />
             </div>
         </div>

         <div style="margin-left: -270px;" class="form-group">
             <div class="col-lg-9 col-lg-offset-3">
                 <button type="submit" name="submit" class="btn btn-warning"
                 style="width: 350px;height: 45px; margin-top:10px;" >立即注册</button>
             </div>
         </div>
     </form>

</div>
<script type="text/javascript">
$(document).ready(function() {
    /**
     * 下面是进行插件初始化
     * 你只需传入相应的键值对
     * */
    $('#defaultForm').bootstrapValidator({
            feedbackIcons: {/*输入框不同状态,显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {/*验证*/
                phone: {/*键名username和input name值对应*/
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '请输入手机号码'
                        } ,
                        regexp: {
                            regexp: /^[0-9]{11}$/,
                            message: '手机号码为11位数字'
                        }/*最后一个没有逗号*/
                    }
                },
                password: {
                    validators: {
                        notEmpty: {
                            message: '请输入密码'
                        },
                        stringLength: {
                            min: 6,
                            max: 16,
                            message: '密码长度必须在6到16之间'
                        }
                    }
                },
                mail: {
                    validators: {
                        notEmpty: {
                            message: '请输入邮箱'
                        },
                        regexp: {
                            regexp: /^\w+@\w+\.(com|cn|net)$/,
                            message: '邮箱格式不正确'
                        }
                    }
                }
            }
            /* submitHandler: function (validator, form, submitButton) {
                alert("submit");
            } */
        }).on('success.form.bv', function(e){//点击提交之后
            // Prevent form submission 应该是阻止表单提交的
            e.preventDefault();
            //自己写的
            $.ajax({
                url:"/appstore/user/saveUser.do",
                type:"post",
                data:$("form").serialize(),
                dataType:"json",
                success:function(i){
                    alert(i);
                    if(i>0){
                        location.reload();
                        alert("注册成功");
                    }
                }
            });
            
        
        });
        
        
});

</script>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值