bootstrap-3.3.7-dist
bootstrapvalidator-master 从这两个文件中引入js组件
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="./bootstrap-3.3.7-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="./bootstrapvalidator-master/dist/css/bootstrapValidator.min.css">
<script type="text/javascript" src = "./bootstrap-3.3.7-dist/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="./bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="./bootstrapvalidator-master/dist/js/bootstrapValidator.min.js"></script>
</head>
<div class="container">
<form class="form-horizontal" name="form1" action='reg1.php' method="post">
<div class="form-group">
<label for="user" class="col-sm-2 control-label">用户名:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="user" name="user" placeholder="请输入用户名">
</div>
</div>
<div class="form-group">
<label for="age" class="col-sm-2 control-label">年龄:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="age" name="age" placeholder="请输入年龄">
</div>
</div>
<div class="form-group">
<label for="pwd" class="col-sm-2 control-label">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" name="pwd" placeholder="请输入密码">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary btn-lg btn-block">注册</button>
</div>
</div>
</form>
</div>
//js样式
notEmpty:非空验证;
numeric:数值验证;
stringLength:字符串长度;
regexp:正则表达式验证
$(function () {
$('form').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
//user名称必须与name名称相同(区分大小写)
user: {
message: '请输入用户名',
validators: {
notEmpty: {
message: '用户名不能为空'
},
stringLength: {
min: 6,
max: 18,
message: '用户名长度必须在6到18位之间'
},
}
},
pwd: {
validators: {
notEmpty: {
message: '密码不能为空'
}
}
},
age:{
validators:{
notEmpty: {
message: '年龄不能为空'
},
numeric:{
message:'必须是数值'
}
}
}
}
});
});