表单验证两种方式:

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的更多相关文章

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

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

  2. jQuery表单验证组件BootstrapValidator

    github:https://github.com/nghuuphuoc/bootstrapvalidator 参考博客:JS组件系列——Form表单验证神器: BootstrapValidator ...

  3. 【前端_js】Bootstrap之表单验证

    Bootstrap表单验证插件bootstrapValidator使用方法整理 BootstrapValidator 表单验证超详细教程    

  4. JS组件系列——Form表单验证神器: BootstrapValidator

    前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...

  5. bootstrapValidator.js,最好用的bootstrap表单验证插件

    前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...

  6. 黄聪: Bootstrap之Form表单验证神器: BootstrapValidator(转)

    前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...

  7. bootstrapValidator表单验证插件

    bootstrapValidator——一个很好用的表单验证插件,再也不用手写验证规则啦! bootstrapValidator官方文档:http://bootstrapvalidator.votin ...

  8. Form表单验证神器: BootstrapValidator

    前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...

  9. Bootstrap学习总结笔记(24)-- 基于BootstrapValidator的Form表单验证

    Form表单进行数据验证是十分必要的,我们可以自己写JS脚本或者使用JQuery Validate 插件来实现.对于Bootstrap而言,利用BootstrapValidator来做Form表单验证 ...

随机推荐

  1. [原]F5负载均衡激活license

    一.pc用网线连接上f5的管理口,开机,ping   192.168.1.245 二.用浏览器登录:https://192.168.1.245     用户名 admin  密码 admin

  2. [Offer收割]编程练习赛15 A.偶像的条件[贪心]

    #1514 : 偶像的条件 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi的学校正面临着废校的大危机.面对学校的危机,小Hi同学们决定从ABC三个班中各挑出一名同 ...

  3. 跟bWAPP学WEB安全(PHP代码)--邮件头和LDAP注入

    背景 由于时间限制和这俩漏洞也不是特别常用,在这里就不搭建环境了,我们从注入原来和代码审计的角度来看看. 邮件头注入 注入原理: 这个地方首先要说一下邮件的结构,分为信封(MAIL FROM.RCPT ...

  4. Java环境变量配置错误

    1,由于Java的环境变量配置错误,导致用到Java的编译过程中出现错误: 改正办法: wget http://download.oracle.com/otn-pub/java/jdk/8u181-b ...

  5. howdoi 简单分析

    对howdoi的一个简单分析. 曾经看到过下面的这样一段js代码: try{ doSth(); } catch (e){ ask_url = "https://stackoverflow.c ...

  6. vue之cli脚手架项目中组件的使用

    在webpack-simple模板中,包括webpck模板.一个.vue文件就是一个组件. 为什么会这样呢?因为webpack干活了!webpack的将我们所有的资源文件进行打包.同时webpack还 ...

  7. java.exe和javaw.exe有什么区别

  8. 极大既然估计和高斯分布推导最小二乘、LASSO、Ridge回归

    最小二乘法可以从Cost/Loss function角度去想,这是统计(机器)学习里面一个重要概念,一般建立模型就是让loss function最小,而最小二乘法可以认为是 loss function ...

  9. Oracle体系结构之数据库启动的不同状态

    数据库启动的不同状态: nomount状态:spfile和plile mount状态:control file open状态:data file和redo file 启动数据库的过程:nomount状 ...

  10. 导入音乐到iPhone

    如果出现iCloud音乐资料库已打开 则需要在手机端设置:打开设置,找到音乐一栏,关闭icloud音乐资料库 http://baijiahao.baidu.com/s?id=1572411750316 ...