如何使用bootstrapVlidator插件?

  1. 下载bootstrapVlidator插件
  2. 在需要使用的页面引入bootstrapVlidator的js文件和css文件

如:

注:

在此基础之前必须引入jquery库和bootstrap的js文件和css样式。

如:

  1. 放入所需插件
  1. 引入路径

3.表单代码:

<form id="registForm">

<!--下面是用户名输入框-->

<div class="form-group">

<div class="input-group">

<span class="input-group-addon" id="basic-addon1">

<span class="glyphicon glyphicon-user"></span>

</span>

<input id="userName" name="username" type="text" class="form-control" placeholder="请输入用户名" aria-describedby="basic-addon1">

</div>

</div>

<br>

<!--下面是邮箱输入框-->

<div class="form-group">

<div class="input-group">

<span class="input-group-addon" id="basic-addon1">

<span class="glyphicon glyphicon-envelope"></span>

</span>

<input id="email" name="email"type="text" class="form-control" placeholder="请输入邮箱">

</div>

</div>

<br>

<!--下面是手机号输入框-->

<div class="form-group">

<div class="input-group">

<span class="input-group-addon" id="basic-addon1">

<span class="glyphicon glyphicon-earphone"></span>

</span>

<input id="phoneNumber" name="phonenumber" type="text" class="form-control" placeholder="请输入手机号">

</div>

</div>

<br>

<!--下面是密码输入框-->

<div class="form-group">

<div class="input-group">

<span class="input-group-addon" id="basic-addon1">

<span class="glyphicon glyphicon-lock"></span>

</span>

<input id="passWord" name="password1" type="text" class="form-control" placeholder="请输入密码">

</div>

</div>

<br>

<!--下面是确认密码输入框-->

<div class="form-group">

<div class="input-group">

<span class="input-group-addon" id="basic-addon1">

<span class="glyphicon glyphicon-lock"></span>

</span>

<input id="passwordTow" name="password2" type="text" class="form-control" placeholder="请重新输入密码">

</div>

</div>

<br>

<!--下面是登陆按钮,包括颜色控制-->

<div class="form-group">

<button type="submit" name="submit" style="width:135px;" onclick="registsubmit()" class="btn btn-primary btn-sm">提交</button>

<button type="reset" id="resetBtn" name="reset" style="width:135px;" class="btn btn-primary btn-sm">重置</button>

</div>

</form>

4.js代码

1.  form里每一个input标签必须要有name属性,是根据name属性的值来设置条件

2.  属性介绍

username:是用户input标签那么的属性值

notEmpty代表不为空验证

Message:写提示语

stringLength:设置字符串长度

regexp:写正则表达式

identical: 相同,用来验证两次密码是否相同

field:写想要相同的mame属性值

//表单验证

 $(function () {

$('form').bootstrapValidator({

message: '请重新输入',

feedbackIcons: {

valid: 'glyphicon glyphicon-ok',

invalid: 'glyphicon glyphicon-remove',

validating: 'glyphicon glyphicon-refresh'

},

fields: {

username: {

message: '用户名验证失败',

validators: {

notEmpty: {

message: '用户名不能为空'

},

stringLength: {

min: 6,

max: 18,

message: '用户名长度必须在6到18位之间'

},

regexp: {

regexp: /^[a-zA-Z0-9_]+$/,

message: '用户名只能包含大写、小写、数字和下划线'

}

}

},

email: {

validators: {

notEmpty: {

message: '邮箱不能为空'

},

emailAddress: {

message: '邮箱地址格式有误'

}

}

},

phonenumber: {

validators: {

notEmpty: {

message: '手机号不能为空'

},

regexp: {

regexp: /^1\d{10}$/,

message: '请输入11为手机号'

}

}

},

password1: {

validators: {

notEmpty: {

message: '密码不能为空'

},

stringLength: {

min: 6,

max: 12,

message: '密码长度必须在6到12位之间'

},

regexp: {

regexp: /^[a-zA-Z0-9_]+$/,

message: '密码只能包含大写、小写、数字和下划线'

},

identical: {

field: 'password2',

message: '两次输入的密码不相符'

}

}

},

password2: {

validators: {

notEmpty: {

message: '密码不能为空'

},

stringLength: {

min: 6,

max: 12,

message: '密码长度必须在6到12位之间'

},

regexp: {

regexp: /^[a-zA-Z0-9_]+$/,

message: '密码只能包含大写、小写、数字和下划线'

},

identical: {

field: 'password1',

message: '两次输入的密码不相符'

}

}

}

},

});

});

如终极效果:

5.重置按钮js写法,包括重置validator验证规则

//重置按钮事件

$("#resetBtn").off().on("click",function(){

$(registForm).data("bootstrapValidator").resetForm();

});

注:"#resetBtn“这个代表重置按钮id值

bootstrap validator 使用 带代码的更多相关文章

  1. BootStrap Validator 版本差异问题导致的submitHandler失效问题的解决方法

    最近一直在做互金平台,做到后台提交表单的时候出现验证提交数据一直没有提交的问题.于是百度了一下.果然是版本问题造成的.幸好找到了问题所在.我一直仿照的是东钿原微信平台的做法,但是使用byond的后台框 ...

  2. 三石推荐!把 Bootstrap 小清新带回家!

    无敌传送门:http://fineui.com/demo_pro/default.aspx?theme=bootstrap1&menu=accordion   喜欢就来赞一个! 把麻烦留给三石 ...

  3. bootstrap表单带验证

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  4. bootstrap validator 出现Maximum call stack size exceeded

    如果用 c# 里面用的是 taghelper 的控件,有可能造成 Maximum call stack size exceeded bootstrap validator  必须是继承  bootst ...

  5. Bootstrap CSS 栅格、代码和表格

    一.bootstrap栅格 Bootstrap 提供了一套响应式.移动设备优先的流式网格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. Bootstrap 网格系统(G ...

  6. bootstrap去除自带15px内边距,去除container 15px padding

     壹 ❀ 问题 在使用bootstrap时,由于bootstrap槽宽特性,我们在布局时会发现container以及col-**-**左右都会自带15px的padding,有时候空间不足就想着怎么把b ...

  7. 用好spring mvc validator可以简化代码

    表单的数据检验对一个程序来讲非常重要,因为对于客户端的数据不能完全信任,常规的检验类型有: 参数为空,根据不同的业务规定要求表单项是必填项 参数值的有效性,比如产品的价格,一定不能是负数 多个表单项组 ...

  8. bootstrap 新手学习笔记 代码整理

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. bootstrap表格多样式及代码

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...

随机推荐

  1. CSS3新特性汇总

    新增选择器 p:nth-child(n){color: rgba(255, 0, 0, 0.75)} 弹性盒模型 display: flex; 多列布局 column-count: 5; 媒体查询 @ ...

  2. JAVAscript学习笔记 jsBOM 第七节 (原创) 参考js使用表

    <html> <head> <title>day02_js</title> <script type="text/javascript& ...

  3. Kotlin实现LeetCode算法题之String to Integer (atoi)

    题目String to Integer (atoi)(难度Medium) 大意是找出给定字串开头部分的整型数值,忽略开头的空格,注意符号,对超出Integer的数做取边界值处理. 方案1 class ...

  4. scala读取parquet文件

    import org.apache.spark.SparkConfimport org.apache.spark.SparkContextimport org.apache.spark.sql.SQL ...

  5. 一:详解 HTTP 协议

    本篇文章篇幅比较长,先来个思维导图预览一下. 一张图带你看完本篇文章 一.概述 1.计算机网络体系结构分层 计算机网络体系结构分层 2.TCP/IP 通信传输流 利用 TCP/IP 协议族进行网络通信 ...

  6. 快速搭建Japser Report

    下列步骤是快速搭建一个Jasper Report,开发中遇到的坑会在下一个博客中提及,如有任何问题,欢迎留言评论 第一步,打开Jaspersoft Studio,界面跟eclispse一样 创建项目: ...

  7. UWP 返回顶部按钮

    返回顶部的按钮,like this 当用户下滑了一定的距离之后,通常是快滑倒底部的时候,出现返回顶部按钮,当用户向上快滑,滑到顶部的时候,返回顶部按钮自动消失. 在UWP中,用来滚动内容的控件是Scr ...

  8. 后台工作者HangFire与ABP框架Abp.Hangfire及扩展

    HangFire与Quartz.NET相比主要是HangFire的内置提供集成化的控制台,方便后台查看及监控,对于大家来说,比较方便. HangFire是什么 Hangfire是一个开源框架(.NET ...

  9. javaScript(JS)强制保留两位小数的输入数校验和小数保留

    参考来源于网络,如有侵权,请联系作者删除: 输入input 的格式校验: $(function(){ var data = $.trim($("#inputId").val()); ...

  10. JavaWeb框架SSH_Struts2_(四)----->表达式语言OGNL

    1. 表达式语言OGNL OGNL简介 OGNL基本语法 常量 操作符 OGNL表达式 OGNL基础 OGNL上下文 OGNL值栈 OGNL的访问 2. 具体内容 2.1 OGNL简介 OGNL(Ob ...