<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>蓝源Eloan-P2P平台->用户注册</title>
<link rel="stylesheet" href="/js/bootstrap-3.3.2-dist/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="/css/core.css" type="text/css" />
<script type="text/javascript" src="/js/jquery/jquery-2.1.3.js"></script>
<script type="text/javascript" src="/js/bootstrap-3.3.2-dist/js/bootstrap.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-validation/localization/messages_zh.js"></script>
<script type="text/javascript" src="/js/plugins/jquery.form.js"></script>
<script type="text/javascript" src="/js/jquery.bootstrap.min.js"></script> <style type="text/css">
.el-register-form{
width:600px;
margin-left:auto;
margin-right:auto;
margin-top: 20px;
}
.el-register-form .form-control{
width: 220px;
display: inline;
}
</style>
<script type="text/javascript">
$(function(){
//第一种Ajax提交表单的方式
//$("#registerForm").ajaxForm();
//执行流程:1,点击表单的提交按钮,2,触发jQuery-validate的验证;
//3,验证成功,jquery-validate会自动提交表单;(因为这个时候表单已经是Ajax表单了,所以表单的提交通过Ajax提交) //自定义jquery-validate验证方法
$.validator.addMethod("checkUsername", function(value, element) {
//这个验证方法返回一个boolean值来代表验证是否通过
var ret=false;
$.ajax({
dataType:"json",
type:"post",
async:false,
url:"/checkUsername.do",
data:{
username:value
},
success:function(data){
ret = data.success;
}
});
return ret;
}, "用户名已经存在!"); $("#registerForm").validate({
rules:{
username:{
required:true,
rangelength:[4,16],
checkUsername:true
},
password:{
required:true,
rangelength:[4,16]
},
confirmPwd:{
equalTo:"#password"
}
},
messages:{
username:{
required:"请输入用户名",
rangelength:"用户名长度为{0}到{1}",
remote:"用户名已经存在"
},
password:{
required:"请输入密码",
rangelength:"密码长度为{0}到{1}"
},
confirmPwd:{
equalTo:"两次输入密码不一致"
}
},
//修改错误提示文字的样式
errorClass:"text-danger",
//处理错误高亮
highlight:function(element,errorClass){
//寻找离自己最近的div
$(element).closest(".form-group").addClass("has-error");
},
//取消错误高亮
unhighlight:function(element,errorClass){
$(element).closest(".form-group").removeClass("has-error");
},
//在表单验证成功之后提交表单做的事情
//第二种Ajax提交表单方式:
//1,点击表单中的提交按钮,2,jquery-valiate执行验证通过;因为这个时候我们配置了submitHandler,所以,当验证成功之后;
//jquery-validate不会自动提交表单,来执行submitHandler,3,在submitHandler中直接使用ajaxSubmit来完成表单提交;
submitHandler:function(form){
$(form).ajaxSubmit({
dataType:"json",
success:function(data){
if(data.success){
$.messager.confirm("提示","注册成功,点击确认进入登录",function(){
window.location.href="/login.html";
});
}else{
$.messager.popup("注册失败,"+data.msg);
}
}
});
}
});
})
</script>
</head>
<body>
<!-- 网页头信息 -->
<div class="el-header" >
<div class="container" style="position: relative;">
<ul class="nav navbar-nav navbar-right">
<li><a href="/">首页</a></li>
<li><a href="/login.html">登录</a></li>
<li><a href="#">帮助</a></li>
</ul>
</div>
</div> <!-- 网页导航 -->
<div class="navbar navbar-default el-navbar">
<div class="container">
<div class="navbar-header">
<a href=""><img alt="Brand" src="/images/logo.png"></a>
<span class="el-page-title">用户注册</span>
</div>
</div>
</div> <!-- 网页内容 -->
<div class="container">
<form id="registerForm" class="form-horizontal el-register-form" action="/register.do" method="post" >
<p class="h4" style="margin: 10px 10px 20px;color:#999;">请填写注册信息,点击“提交注册”即可完成注册!</p>
<div class="form-group">
<label class="control-label col-sm-2">用户名</label>
<div class="col-sm-10">
<input type="text" autocomplete="off" name="username" class="form-control" id="username"/>
<p class="help-block">用户名为4~16位字母,数字,符号或中文</p>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">密&emsp;码</label>
<div class="col-sm-10">
<input type="password" autocomplete="off" name="password" id="password" class="form-control" />
<p class="help-block">密码为4~16位字符组成,采用数字、字母、符号安全性更高</p>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">确认密码</label>
<div class="col-sm-10">
<input type="password" autocomplete="off" name="confirmPwd" class="form-control" />
<p class="help-block">请再次填写密码</p>
</div>
</div>
<div class="form-gorup">
<div class="col-sm-offset-2">
<button type="submit" class="btn btn-success">
同意协议并注册
</button>
&emsp;&emsp;
<a href="/login.html" class="text-primary">已有账号,马上登录</a> <p style="padding-left: 50px;margin-top: 15px;">
<a href="#">《使用协议说明书》</a>
</p>
</div>
</div>
</form>
</div>
<!-- 网页版权 -->
<div class="container-foot-2">
<div class="context">
<div class="left">
<p>专注于高级Java开发工程师的培养</p>
<p>版权所有:&emsp;2015广州小码哥教育科技有限公司</p>
<p>地&emsp;&emsp;址:&emsp;广州市天河区棠下荷光三横路盛达商务园D座5楼</p>
<p>电&emsp;&emsp;话: 020-29007520&emsp;&emsp;
邮箱:&emsp;service@520it.com</p>
<p>
<a href="http://www.miitbeian.gov.cn" style="color: #ffffff">ICP备案
:粤ICP备字1504547</a>
</p>
<p>
<a href="http://www.gzjd.gov.cn/wlaqjc/open/validateSite.do" style="color: #ffffff">穗公网安备:44010650010086</a>
</p>
</div>
<div class="right">
<a target="_blank" href="http://weibo.com/ITxiaomage"><img
src="/images/sina.png"></a>
</div>
<div class="clearfix"></div>
</div>
</div>
</body>
</html>

通过jquery.validate.js校验表单字段是否合法的更多相关文章

  1. jquery.validate.js校验select2解决方案,Jquery插件select2校验解决方案

    jquery.validate.js校验select2解决方案 Jquery插件select2校验解决方案 >>>>>>>>>>>&g ...

  2. jquery.validate.js 验证表单时,在IE当中未验证就直接提交的原因

    jquery.validate.js 验证表单时,在IE当中未验证就直接提交的原因 今天利用了jquery.validate.js来验证表单,发现在火狐.谷歌浏览器当中都可以进行验证,但是在IE系列浏 ...

  3. 表单提交学习笔记(二)—使用jquery.validate.js进行表单验证

    一.官网下载地址:http://plugins.jquery.com/validate/ 二.用法 1.在页面上进行引用 <script src="~/scripts/jquery-1 ...

  4. jquery.validate.js自定义表单验证

    $(document).ready(function() { //在下列位置输入页面加载的逻辑代码 $("#inputForm").validate({ rules: { seq: ...

  5. Django 表单校验 表单字段设置 自定义表单校验规则

    今天看到了一篇非常好的博文,拿来和大家分享一下. 内容包括了: 用户注册时输入数据的校验 使用widget进行字段设置 实现自定义的校验规则 参考自下面的这篇文章

  6. 使用jquery.validate.js实现boostrap3的校验和验证

    使用jquery.validate.js实现boostrap3的校验和验证 boostrap3验证框架 jquery.validate.js校验表单 >>>>>>& ...

  7. jquery.validate.js默认配置,jquery.validate.js自定义提示信息

    jquery.validate.js默认配置,jquery.validate.js自定义提示信息 配置jQuery.validator默认的处理方法 >>>>>>& ...

  8. jquery.validate.js表单验证

    一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...

  9. 【转】jquery.validate.js表单验证

    一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...

随机推荐

  1. 开发环境解决 kafka Failed to send messages after 3 tries

    新建了一个kafka集群,在window下写了一个简单的producer做测试,结果遇到了消息发送失败的问题,代码如下: Properties props = new Properties(); pr ...

  2. 【leetcode】300.Longest Increasing Subsequence

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  3. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

  4. webgl example1

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  5. PHP中面向对象编程思想的3个特征

    面向对象编程思想的3个特征: 封装: 无非是一个大的指向思想,目的是为了将一个类设计得更为健壮! 其基本做法是: 尽可能地将一个类的成员私有化,只开放那些必不可少的对外的属性或方法,能private的 ...

  6. apache常用的两种工作模式 prefork和worker

    apache作为现今web服务器用的最广泛也是最稳定的开源服务器软件,其工作模式有许多中,目前主要有两种模式:prefork模式和worker模式 一.两种模式 prefork模式: prefork是 ...

  7. 第204天:js---重载和多态

    一.根据arguments个数实现重载 js本身不支持重载,所以只能通过其他方式实现,arguments检测传参的个数,然后再执行不同的方式 function add() { var sum = 0 ...

  8. Spring Boot 初步小结

    Spring Boot 是一种开发模式,不涉及任何新的技术 1.了解自动配置的原理 2.常用application.yml文件的配置项 3.Spring Boot 及 第三方提供的各种 starter ...

  9. RGB555转RGB565

    做tft彩屏显示图片的时候,显示16位位图,显示屏的显示模式为RGB565.使用img2lcd转换后的16位bmp,显示出来后,颜色有偏差:转换为565格式的bin文件,显示完全正常,可以确定转换为b ...

  10. varnish启动报错

    错误1.Starting Varnish Cache: Error: Cannot open socket: :80: Address family not supported by protocol ...