1. 表单验证插件-----Validation

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script src="lib/jquery.validate.js" type="text/javascript"></script>
<style type="text/css">
*
{
font-family: Verdana;
font-size: 96%;
}
label
{
width: 10em;
float: left;
}
label.error
{
float: none;
color: red;
padding-left: .5em;
vertical-align: top;
}
p
{
clear: both;
}
.submit
{
margin-left: 12em;
} em
{
font-weight: bold;
padding-right: 1em;
vertical-align: top;
}
em.error
{
background: url("images/unchecked.gif") no-repeat 0px 0px;
padding-left: 16px;
}
em.success
{
background: url("images/checked.gif") no-repeat 0px 0px;
padding-left: 16px;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
//自定义一个验证方法
$.validator.addMethod(
"formula", //验证方法名称
function (value, element, param) {//验证规则
return value == eval(param);
},
'请正确输入数学公式计算后的结果'//验证提示信息
);
$("#commentForm").validate({
rules: {
username: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
url: "url",
comment: "required",
valcode: {
formula: "7+9"
}
},
messages: {
username: {
required: '请输入姓名',
minlength: '请至少输入两个字符'
},
email: {
required: '请输入电子邮件',
email: '请检查电子邮件的格式'
},
url: '请检查网址的格式',
comment: '请输入您的评论'
},
errorElement: "em", //用来创建错误提示信息标签
success: function (label) { //验证成功后的执行的回调函数
//label指向上面那个错误提示信息标签em
label.text(" ") //清空错误提示消息
.addClass("success"); //加上自定义的success类
}
});
});
</script>
</head>
<body>
<form class="cmxform" id="commentForm" method="get" action="">
<fieldset>
<legend>一个简单的验证带验证提示的评论例子</legend>
<p>
<label for="cusername">姓名</label>
<em>*</em><input id="cusername" name="username" size="25" />
</p>
<p>
<label for="cemail">电子邮件</label>
<em>*</em><input id="cemail" name="email" size="25" />
</p>
<p>
<label for="curl">网址</label>
<em></em>
<input id="curl" name="url" size="25" value="" />
</p>
<p>
<label for="ccomment">你的评论</label>
<em>*</em><textarea id="ccomment" name="comment" cols="22"></textarea>
</p>
<p>
<label for="cvalcode">验证码</label>
<input id="cvalcode" name="valcode" size="25" value="" />=7+9
</p>
<p>
<input class="submit" type="submit" value="提交" />
</p>
</fieldset>
</form>
</body>
</html>

  2.表单验证插件-----Validation Engine

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Validation Engine 表单验证中文版 &raquo; 在线演示 - 前端开发仓库</title>
<link rel="stylesheet" href="/css/demo.css">
<link rel="stylesheet" href="css/validationEngine.jquery.css">
<link rel="stylesheet" href="css/layout.css">
</head>
<body>
<div class="wrap">
<div class="side">
<div class="logo">
<a href="http://code.ciaoca.com/" target="_blank">前端开发仓库</a>
<em>在线演示</em>
</div>
</div>
<div class="main">
<div class="inwrap">
<h1>jQuery Validation Engine 表单验证中文版</h1>
<h2>较好体验的中文表单</h2> <div class="detail">
<p>示例中经过样式调整,以及使用部分参数来提高用户体验。</p>
</div> <div class="example">
<form id="user_form" class="user_form formular" method="post">
<fieldset>
<legend>账号资料</legend>
<dl class="form_add">
<dt>用户名</dt>
<dd><input class="text-input validate[required]" type="text"></dd>
<dt>密码</dt>
<dd><input class="text-input validate[required,minSize[6],maxSize[20]]" type="password" id="pwd"></dd>
<dt>确认密码</dt>
<dd><input class="text-input validate[condRequired[pwd],equals[pwd]]" type="password"></dd>
</dl>
</fieldset> <fieldset>
<legend>个人信息</legend>
<dl class="form_add">
<dt>姓名</dt>
<dd><input class="text-input validate[required,custom[chinese],minSize[2]]" type="text" id="name"></dd>
<dt>出生日期</dt>
<dd><input class="text-input validate[required,custom[date]]" type="text"></dd>
<dt>手机号码</dt>
<dd><input class="text-input validate[required,custom[phone]]" type="text"></dd>
<dt>身份证号码</dt>
<dd><input class="text-input validate[required,custom[chinaId]]" type="text"></dd>
<dt>QQ</dt>
<dd><input class="text-input validate[required,custom[qq]]" type="text"></dd>
<dt>E-mail</dt>
<dd><input class="text-input validate[required,custom[email]]" type="text"></dd>
<dt>网站/博客</dt>
<dd><input class="text-input validate[required,custom[url]]" type="text"></dd>
</dl>
</fieldset> <fieldset>
<legend>收件人信息</legend>
<dl class="form_add">
<dt>所在地</dt>
<dd>
<select class="validate[required]">
<option value="">请选择</option>
<option value="option1">国内</option>
<option value="option2">国外</option>
</select>
</dd>
<dt>街道地址</dt>
<dd><input class="text-input validate[required,minSize[10]]" type="text"></dd>
<dt>邮编</dt>
<dd><input class="text-input validate[required,custom[chinaZip]]" type="text"></dd>
</dl>
</fieldset> <fieldset>
<legend>其他</legend>
<dl class="form_add">
<dt>验证码</dt>
<dd><input class="text-input validate[required,ajax[ajaxVerify]]" type="text" style="width:100px;" data-prompt-position="centerRight:100,0"> <img src="img/verify.jpg" width="90" height="26"></dd>
<dt></dt>
<dd><input class="radio validate[required]" type="checkbox" id="agree" name="agree" data-prompt-position="centerRight:80,0"> <label for="agree">同意用户协议</label></dd>
</dl>
</fieldset> <input class="submit" type="submit" value="验证 & 提交表单">
</form>
</div> </div>
</div>
</div> <script src="/js/jquery-1.7.2.min.js"></script>
<script src="js/languages/jquery.validationEngine-zh-CN-ciaoca.js"></script>
<script src="js/jquery.validationEngine.min.js"></script>
<script>
$.validationEngineLanguage.allRules.ajaxVerify={
url: 'phpajax/ajaxValidateVerify.php',
extraData: 'name=eric',
alertTextOk: '<strong style="color:#090;">√<strong>',
alertText: '<strong>×</strong>',
alertTextLoad: ''
}; jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
jQuery('#user_form').validationEngine({
scroll: false,
//binded: false,
//showArrow: false,
promptPosition: 'centerRight',
maxErrorsPerField: 1,
showOneMessage: true,
addPromptClass: 'formError-noArrow formError-text',
custom_error_messages: {
'#pwd': {
'minSize': {
'message': '* 密码不得少于 6 位,建议使用英文与数字组合'
}
}
}
});
});
</script>
</body>
</html>

第九章 jQuery验证插件简介的更多相关文章

  1. jQuery验证插件

    原文:jQuery验证插件 学习要点: 1.使用 validate.js 插件 2.默认验证规则 3.validate()方法和选项 4.validate.js 其他功能 验证插件(validate. ...

  2. 三、jQuery--jQuery基础--jQuery基础课程--第9章 jQuery 常用插件

    1.表单验证插件——validate 该插件自带包含必填.数字.URL在内容的验证规则,即时显示异常信息,此外,还允许自定义验证规则,插件调用方法如下:$(form).validate({option ...

  3. jQuery验证插件使用初步

    validate是一款优秀的表单验证插件,其初步使用方法如下: (1)前台页面代码: <form id="form1" runat="server"> ...

  4. jQuery验证插件 Validate详解

    1.引入必要的文件,以及语言中文提示包 2.使用规则如下: 序号 规则 描述 1 required:true 必须输入的字段. 2 remote:"check.php" 使用 aj ...

  5. Jquery验证插件 JqueryValidation 动态验证用户名等

    可以参考:http://www.w3cschool.cc/jquery/jquery-plugin-validate.html //form1 验证用户名 $("#form1"). ...

  6. form 表单jquery验证插件使用

    第一部分:表单样式 <form action="#" method="post" id="regist">   <tabl ...

  7. jquery 验证插件 validate

    1)required:true 必输字段(2)remote:"check.php" 使用ajax方法调用check.php验证输入值(3)email:true 必须输入正确格式的电 ...

  8. jquery验证插件validate自定义扩展

    <script src="${pageContext.request.contextPath}/resources/js/jquery-1.12.0.min.js" type ...

  9. SPRING IN ACTION 第4版笔记-第九章Securing web applications-001-SpringSecurity简介(DelegatingFilterProxy、AbstractSecurityWebApplicationInitializer、WebSecurityConfigurerAdapter、@EnableWebSecurity、@EnableWebMvcS)

    一.SpringSecurity的模块 At the least, you’ll want to include the Core and Configuration modules in your ...

随机推荐

  1. 多浏览器兼容flv视频播放HTML

    HTML: <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http: ...

  2. Java计算日期和时间差

    这篇文章将使用两个例子计算两个日期的时间差.1.使用Java SDK.2.使用Joda库.1.使用Java SDK 计算两个Date之间的时间差,基本思路为把Date转换为ms(微秒),然后计算两个微 ...

  3. python常用字符串操作

    #!/usr/bin/env python name='cunzhang' print(name.capitalize())#首字母大写 print(name.count('n'))#统计字符有几个 ...

  4. C#多线程开发

    1.进程与线程的区别 通俗的讲,进行就是任务管理器中进行列表中看到的正在运行的程序,它是一个动态的概念,活动的实体. 线程是程序执行流的最小单元,是线程中一个实体,是系统独立调度和分派CPU基本单位. ...

  5. 用Spring3编写第一个HelloWorld项目

    第一个HelloWorld程序 让我们用Spring来写第一个应用程序吧. 完成这一章要求: 熟悉Java语言 设置好Spring的环境 熟悉简单的Eclipse IDE的操作 如果你还没有设置好环境 ...

  6. Android 监听屏幕锁屏,用户解锁

    在做一个程序的时候,需要时刻保持某一服务是启动的,因此想到了通过监听屏幕SCREEN_ON和SCREEN_OFF这两个action.奇怪的是,这两个action只能通过代码的形式注册,才能被监听到,使 ...

  7. Codeforces Gym 100425A Luggage Distribution 二分 数学

    A - Luggage DistributionTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  8. Ununtu 12.04 gedit安装插件Source Code Browser

    1. 安装ctags: sudo apt-get install exuberant-ctags 2. 打开https://github.com/Quixotix/gedit-source-code- ...

  9. [AngularJS] ui-router: Abstract States

    ui-router has the powerful ability to define abstract states, or states that can't be navigated to, ...

  10. [MEAN Stack] First API -- 4. Organize app structure

    The app structure: Front-end: app.js /** * Created by Answer1215 on 12/9/2014. */ 'use strict'; func ...