表单验证——JqueryValidator、BootstrapValidator
表单验证两种方式:
1、JqueryValidator
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JqueryValidator实战——用户注册</title>
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script> </head>
<body>
<form id="signUpForm">
<label for="username">username:</label>
<br>
<input type="text" id="username" name="username">
<br>
<label for="password">password:</label>
<br>
<input type="password" id="password" name="password">
<br>
<label for="confirmPassword">confirm:</label>
<br>
<input type="password" id="confirmPassword" name="confirmPassword">
<br>
<input type="submit" value="Submit" class="submit">
</form>
<script>
$.validator.setDefaults({
submitHandler: function() {
alert("提交事件!");
}
});
$().ready(function(){
$("#signUpForm").validate({
debug:true,
rules:{
username:"required",
password:{
required: true,
minlength: 5
},
confirmPassword: {
required: true,
minlength: 5,
equalTo: "#password"
}
},
messages:{
username:"用户名"
}
});
}); </script>
</body>
</html>
2、BootstrapValidator
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>BootstrapValidator表单验证Test</title>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css"/>
<link rel="stylesheet" href="bower_components/bootstrapValidator/dist/css/bootstrapValidator.min.css"/> <script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <script type="text/javascript" src="bower_components/bootstrapValidator/dist/js/bootstrapValidator.min.js"></script>
</head>
<body>
<form class="registerForm col-xs-5">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" name="username" />
</div>
<div class="form-group">
<label>Email address</label>
<input type="text" class="form-control" name="email" />
</div>
<input type="submit" value="Submit" class="submit">
</form> <script>
$(document).ready(function() {
$('.registerForm').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
username: {
message: 'The username is not valid',
validators: {
notEmpty: {
message: 'The username is required and cannot be empty'
},
stringLength: {
min: 6,
max: 30,
message: 'The username must be more than 6 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_]+$/,
message: 'The username can only consist of alphabetical, number and underscore'
}
}
},
email: {
validators: {
notEmpty: {
message: 'The email is required and cannot be empty'
},
emailAddress: {
message: 'The input is not a valid email address'
}
}
}
}
});
});
</script>
</body>
</html>
几点区别:
1、BootstrapValidator因为使用到了bootstrap定义的样式,美观程度上略胜一筹;
2、BootstrapValidator默认支持正则表达式,可根据业务逻辑设计自定义的正则表达式,而jqueryValidator默认不支持正则,需要手动添加addMethod("regex",xxx);见http://stackoverflow.com/questions/280759/jquery-validate-how-to-add-a-rule-for-regular-expression-validation
3、其他方面,如添加验证规则的语法上,两者基本一样,可以在html中设置属性,也可以在js中设置。
表单验证——JqueryValidator、BootstrapValidator的更多相关文章
- Bootstrap表单验证插件bootstrapValidator使用方法整理
插件介绍 先上一个图: 下载地址:https://github.com/nghuuphuoc/bootstrapvalidator 使用方法:http://www.cnblogs.com/huangc ...
- jQuery表单验证组件BootstrapValidator
github:https://github.com/nghuuphuoc/bootstrapvalidator 参考博客:JS组件系列——Form表单验证神器: BootstrapValidator ...
- 【前端_js】Bootstrap之表单验证
Bootstrap表单验证插件bootstrapValidator使用方法整理 BootstrapValidator 表单验证超详细教程
- JS组件系列——Form表单验证神器: BootstrapValidator
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
- bootstrapValidator.js,最好用的bootstrap表单验证插件
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
- 黄聪: Bootstrap之Form表单验证神器: BootstrapValidator(转)
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
- bootstrapValidator表单验证插件
bootstrapValidator——一个很好用的表单验证插件,再也不用手写验证规则啦! bootstrapValidator官方文档:http://bootstrapvalidator.votin ...
- Form表单验证神器: BootstrapValidator
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
- Bootstrap学习总结笔记(24)-- 基于BootstrapValidator的Form表单验证
Form表单进行数据验证是十分必要的,我们可以自己写JS脚本或者使用JQuery Validate 插件来实现.对于Bootstrap而言,利用BootstrapValidator来做Form表单验证 ...
随机推荐
- 如何清除 DBA_DATAPUMP_JOBS 视图中的异常数据泵作业
解决方案 用于这个例子中的作业: - 导出作业 SCOTT.EXPDP_20051121 是一个正在运行的 schema 级别的导出作业 - 导出作业 SCOTT.SYS_EXPORT_TABLE_0 ...
- Eclipse的控制台console经常闪现
Eclipse的控制台console有时候经常闪现! 让它不经常的调出来,可以按下面的操作去掉它: windows -> preferences -> run/debug ...
- rabbitmq在centos 7上的安装
一.安装步骤 参考了官网文档: http://www.rabbitmq.com/install-rpm.html#package-dependencies 这里大概介绍下. rabbitmq-serv ...
- Unix/Linux 查看文件大小
ls -l help.html-rw-r--r-- 1 william wheel 40960 Jul 18 00:59 development.sqlite3 40960 就是文件的大小. d ...
- MassTransit
http://stackoverflow.com/questions/15485317/newbie-is-a-consumer-queue-necessary-in-order-for-publis ...
- 关于在Linux下apache-maven的安装
本文所涉及到的软件如下:jdk版本号:1.7.0_45apache-maven版本号:3.1.1 apache-maven的安装过程如下: apache-maven的官方网址:http://maven ...
- React Native ——入门环境搭配以及简单实例
一.Homebrew 是OS X 的套件管理器. 首先我们需要获取 Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent. ...
- 7.19python昨日复习和多线程
关于GIL锁的经典面试题!!
- CentOS7.5搭建Solr7.4.0单机服务
一.Solr安装环境 1.官方参考文档 Solr教程参考指南:http://lucene.apache.org/solr/guide/7_4/solr-tutorial.html 2.Solr运行环境 ...
- VS2015 中使用 MVC4
最近把机子升级到win10 觉得还是好用, 又看了一个vs最新版,于时就安了个vs2015 可以前MVC4的项目用不起了 System.Web.Mvc这个有叹号,生成还要报错, 看了一下原因找不到4. ...