一、实时验证用户名是否存在,密码不能和用户名相同,两次密码需要相同,提交之后需要验证返回值

<form id="defaultForm" role="form" class="form-signin" action="registerAccount.do"
method="post">
<h2 class="form-signin-heading">请输入注册信息:</h2> <div class="form-group">
<label for="username">用户名:</label><input class="form-control"
type="text" name="username" id="username" />
</div>
<div class="form-group">
<label for="password">密码:</label><input class="form-control"
type="password" name="password" id="password"/>
</div>
<div class="form-group">
<label for="repassword">确认密码:</label><input class="form-control"
type="password" name="repassword" id="repassword" />
</div>
<div class="form-group">
<label for="phone">手机号码:</label><input class="form-control"
type="text" name="phone" id="phone" />
</div>
<div class="form-group">
<label for="email">email:</label><input class="form-control"
type="email" name="email" id="email" />
</div>
<div class="form-group">
<label for="invite">邀请码:</label><input class="form-control"
type="text" name="invite" id="invite">
</div>
<div class="form-group">
<button class="btn btn-lg btn-primary btn-block" type="submit">确认注册</button>
<a class="btn btn-lg btn-primary btn-block" href="../">返回首页</a>
</div>
</form>

$(function(){/* 文档加载,执行一个函数*/
$('#defaultForm')
.bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {/*input状态样式图片*/
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
username: {//验证input项:验证规则
message: 'The username is not valid', validators: {
notEmpty: {//非空验证:提示消息
message: '用户名不能为空'
},
stringLength: {
min: 6,
max: 30,
message: '用户名长度必须在6到30之间'
},
threshold : 6 , //有6字符以上才发送ajax请求,(input中输入一个字符,插件会向服务器发送一次,设置限制,6字符以上才开始)
remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值,获得一个json数据。属性固定,例表示正确:{"valid",true}
url: 'exist2.do',//验证地址
message: '用户已存在',//提示消息
delay : 2000,//每输入一个字符,就发ajax请求,服务器压力还是太大,设置2秒发送一次ajax(默认输入一个字符,提交一次,服务器压力太大)
type: 'POST'//请求方式
/**自定义提交数据,默认值提交当前input value
* data: function(validator) {
return {
password: $('[name="passwordNameAttributeInYourForm"]').val(),
whatever: $('[name="whateverNameAttributeInYourForm"]').val()
};
}
*/
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: '用户名由数字字母下划线和.组成'
}
}
},
password: {
message:'密码无效',
validators: {
notEmpty: {
message: '密码不能为空'
},
stringLength: {
min: 6,
max: 30,
message: '用户名长度必须在6到30之间'
},
identical: {//相同
field: 'repassword', //需要进行比较的input name值
message: '两次密码不一致'
},
different: {//不能和用户名相同
field: 'username',//需要进行比较的input name值
message: '不能和用户名相同'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The username can only consist of alphabetical, number, dot and underscore'
}
}
},
repassword: {
message: '密码无效',
validators: {
notEmpty: {
message: '用户名不能为空'
},
stringLength: {
min: 6,
max: 30,
message: '用户名长度必须在6到30之间'
},
identical: {//相同
field: 'password',
message: '两次密码不一致'
},
different: {//不能和用户名相同
field: 'username',
message: '不能和用户名相同'
},
regexp: {//匹配规则
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The username can only consist of alphabetical, number, dot and underscore'
}
}
},
email: {
validators: {
notEmpty: {
message: '邮件不能为空'
},
emailAddress: {
message: '请输入正确的邮件地址如:123@qq.com'
}
}
},
phone: {
message: 'The phone is not valid',
validators: {
notEmpty: {
message: '手机号码不能为空'
},
stringLength: {
min: 11,
max: 11,
message: '请输入11位手机号码'
},
regexp: {
regexp: /^1[3|5|8]{1}[0-9]{9}$/,
message: '请输入正确的手机号码'
}
}
},
invite: {
message: '邀请码',
validators: {
notEmpty: {
message: '邀请码不能为空'
},
stringLength: {
min: 8,
max: 8,
message: '请输入正确长度的邀请码'
},
regexp: {
regexp: /^[\w]{8}$/,
message: '请输入正确的邀请码(包含数字字母)'
}
}
},
}
})
.on('success.form.bv', function(e) {//点击提交之后
// Prevent form submission
e.preventDefault(); // Get the form instance
var $form = $(e.target); // Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator'); // Use Ajax to submit form data 提交至form标签中的action,result自定义
$.post($form.attr('action'), $form.serialize(), function(result) {
//do something...
});
});
});

二、新密码不能和旧密码一致,确认密码必须和新密码一致

passwordSignUp: {
validators: {
notEmpty: {
message: '密码不能为空'
},
stringLength: {
min: 6,
max: 30,
message: '密码长度必须大于6位,小于30位'
},
regexp: {
regexp: /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,30}$/,
message: '密码必须包含数字、字母和字符'
},
identical: {
field: 'passwordSignUp_confirm',
message: '两次输入的密码不相符'
},
different: {
field: 'usernameSignUp',
message: '不能使用用户名作为密码'
}
}
},
passwordSignUpConfirm: {
validators: {
notEmpty: {
message: '密码不能为空'
},
identical: {
field: 'passwordSignUp',
message: '两次输入的密码不相符'
},
different: {
field: 'usernameSignUp',
message: '不能使用用户名作为密码'
}
}
}

三、动态添加和移除验证项(校验、校验清除重置)

$('#add-user-modal-form').data('bootstrapValidator').enableFieldValidators('addUserModalUserName', true);

其中“addUserModalUserName”为验证项name。

四、纯数字验证:

digits: {
message: '该值只能包含整数。'
}

number:{message: '该值只能包含数字。'}//浮点数和整数验证;

五、判断输入数字是否符合大于18小于100:

greaterThan: {
value: 18
},
lessThan: {
value: 100
}

六、复选框验证:

choice: {
min: 2,
max: 4,
message: '请选择2-4项'
}

七、属性方式校验

<input type="text" class="form-control" name="username"
data-bv-message="The username is not valid"
required
data-bv-notempty-message="The username is required and cannot be empty"
pattern="^[a-zA-Z0-9]+$" data-bv-regexp-message="The username can only consist of alphabetical and digits"
data-bv-stringlength="true"
data-bv-stringlength-min="6"
data-bv-stringlength-max="30"
data-bv-stringlength-message="The username must be more than 6 and less than 30 characters long"
data-bv-different="true"
data-bv-different-field="password"
data-bv-different-message="The username and password cannot be the same as each other"
data-bv-remote="true"
data-bv-remote-url="remote.php"
data-bv-remote-message="The username is not available"
/>

八、验证file类型的表单元素:

addSoftModalFile: {
message: '软件无效',
validators: {
notEmpty: {
message: '上传文件不能为空'
},
file: {
extension: 'rar,tar,zip,gz,bz2',
mimeTypes: '.rar,.tar,.zip,.gz,.bz2',
message: '文件类型为.rar,.tar,.zip,.gz,.bz2'
}
}
}

九、其它:

emailAddress:邮箱地址验证;

base64:64位编码验证;

creditCard:身份证验证;

phone:电话号码验证;

api地址:http://bootstrapvalidator.votintsev.ru/validators/

基于jquery、bootstrap的数据验证插件bootstrapValidator使用的更多相关文章

  1. 基于jquery,bootstrap数据验证插件bootstrapValidator 教程

    bootstrap:能够增加兼容性的强大框架. 因为项目需要数据验证,看bootstrapValidator 还不错,就上手一直,完美兼容,话不多说. 需要引用css: bootstrap.min.c ...

  2. 基于jquery,bootstrap数据验证插件bootstrapValidator

    bootstrap:能够增加兼容性的强大框架. 因为项目需要数据验证,看bootstrapValidator 还不错,就上手一直,完美兼容,话不多说. 需要引用css: bootstrap.min.c ...

  3. 【转】基于jquery,bootstrap数据验证插件bootstrapValidator 教程

    bootstrap:能够增加兼容性的强大框架. 因为项目需要数据验证,看bootstrapValidator 还不错,就上手一直,完美兼容,话不多说. 需要引用css: bootstrap.min.c ...

  4. Bootstrap表单验证插件bootstrapValidator使用方法整理

    插件介绍 先上一个图: 下载地址:https://github.com/nghuuphuoc/bootstrapvalidator 使用方法:http://www.cnblogs.com/huangc ...

  5. jquery数据验证插件

    jquery数据验证插件(自制,简单,练手)   一:最近项目中js数据验证比较多,为了统一风格,移植复用,于是顺手封装了Jquery的插件. (function($) { var defaults ...

  6. 基于jquery的提示框JavaScript 插件,类Bootstrap

    目录 基于jquery的提示框JavaScript 插件,类Bootstrap 基于jquery的提示框JavaScript 插件,类Bootstrap 源码 github地址: https://gi ...

  7. 推荐20款基于 jQuery & CSS 的文本效果插件

    jQuery 和 CSS 可以说是设计和开发行业的一次革命.这一切如此简单,快捷的一站式服务.jQuery 允许你在你的网页中添加一些真正令人惊叹的东西而不用付出很大的努力,要感谢那些优秀的 jQue ...

  8. jQuery formValidator表单验证插件

    什么是jQuery formValidator? jQuery formValidator表单验证插件是客户端表单验证插件. 在做B/S开发的时候,我们经常涉及到很多表单验证,例如新用户注册,填写个人 ...

  9. 基于 Vue BootStrap的迷你Chrome插件

    代码地址如下:http://www.demodashi.com/demo/14306.html 安装 安装 Visual Studio Code 和Chrome, 自行FQ 详细安装这里略过 安装包管 ...

随机推荐

  1. mv 命令

    [root@localhost soft]# .txt [root@localhost soft]# [root@localhost soft]# ls .txt [root@localhost so ...

  2. awk命令分析日志的简单笔记

    awk是一个文本分析工具,可以用来进行流量日志分析 之前无意中看到了这个命令,简单记一下笔记 ,在打线下的时候可能会有用 awk有3个不同版本: awk.nawk和gawk,未作特别说明,一般指gaw ...

  3. 【LeetCode每天一题】Reverse Integer(反转数字)

    Given a 32-bit signed integer, reverse digits of an integer. Example 1:                              ...

  4. 时间序列模式(ARIMA)---Python实现

    时间序列分析的主要目的是根据已有的历史数据对未来进行预测.如餐饮销售预测可以看做是基于时间序列的短期数据预测, 预测的对象时具体菜品的销售量. 1.时间序列算法: 常见的时间序列模型; ​ 2.时序模 ...

  5. python内置函数值 -- chr() ord()

    chr()接收一个数字, 找到这个数字对应的ascii里的元素(只能接受数字) a = chr(65) print(a) #结果: A ord()接收一个字符,返回这个字符对应的数字.(只能接受一个字 ...

  6. PHP开启mysqli扩展

    Call to undefined function mysqli_connect()解决这个问题需要开启mysqli扩展开启mysqli扩展需要这两个步骤缺一不可1.在php.ini中搜索php_m ...

  7. Spring框架第一天

    ## 今天课程:Spring框架第一天 ## ---------- **Spring框架的学习路线** 1. Spring第一天:Spring的IOC容器之XML的方式,Spring框架与Web项目整 ...

  8. 字符串转化为int数组

    String a = "1,2,3,4,5,6" String str[] = a.split(","); int array[] = new int[str. ...

  9. C#学习入门第一篇

    1. using System; using System.Collections.Generic; using System.Ling; using System.Text; using Syste ...

  10. 第零章 HTML启蒙知识与网站开发流程

    Web前端启蒙知识:1.软件架构模式a)B/S架构:Browser-Server 浏览器服务器模型b)C/S架构:Client-Server 客户端服务器模型注1:浏览器是运行网页的应用程序注2:B/ ...