表单验证插件

bootstrap-validator 表单验证插件

$(function(){  //入口函数
      //查找页面id是form的表单 绑定插件
      $("#form").bootstrapValidator({
             //2. 指定校验时的图标显示,默认是bootstrap风格
  feedbackIcons: {
      valid: 'glyphicon glyphicon-ok',  //校验成功
      invalid: 'glyphicon glyphicon-remove',   //校验失败
      validating: 'glyphicon glyphicon-refresh'  //校验中
    },


            //配置字段        //配置的字段与input中的 name="username"是关联的
            fields:{
                  username:{
                        //配置校验规则
                        validators:{
                              notEmpty:{message:"用户名不能为空" }, //非空
                              stringLength:{ min:2 ,max:6, message:"用户名长度必须在2~6位"}   //长度校验
                        }
                  },
                  password:{
                        validators:{
                              notEmpty:{message:"密码不能为空"},
                              stringLength:{ min:6, max:12,message:"密码长度必须是6~12位"}
                        }
                  }
            }
      });
})

猜你喜欢

转载自www.cnblogs.com/javascript9527/p/11707449.html
今日推荐