原帖地址:http://www.cnblogs.com/talk/archive/2012/01/29/2330887.html

$(function () {
try {
$.formValidator.initConfig({
formid: "formTable",
errorfocus: false,
submitonce: true,
tipstyle: "both",
onerror: function () { // 验证不通过时的回调函数
alert("红色提示处输入非法,请根据提示修改!");
}
});
//验证字符串(必填)
$("#name").formValidator({ // 验证:模块名称
onshow: "(必填)",
onfocus: "(必填)不超过50个字符",
oncorrect: "(正确)"
}).inputValidator({
min: 1,
max: 50,
onerrormin: "(错误)不能为空",
onerrormax: "(错误)不超过50个字符,汉字算两个字符"
}); //验证字符串(选填)
$("#name").formValidator({ // 验证:模块名称
onshow: "(选填)",
onfocus: "(选填)不超过50个字符",
oncorrect: "(正确)",
empty: true
}).inputValidator({
min: 1,
max: 50,
onerrormin: "(错误)不能为空",
onerrormax: "(错误)不超过50个字符,汉字算两个字符"
}); //验证时间
$("#addDate").formValidator({ // 验证:发送时间
onshow: "(必填)",
onfocus: "(必填)请选择操作时间",
oncorrect: "(正确)"
}).functionValidator({
fun: function (val, elem) {
if (!/^\d{4}-\d{2}-\d{2}[ ]\d{2}:\d{2}$/.test(val)) {
return "(错误)请选择操作时间";
}
return true;
}
}); //ajax验证
$("#account").formValidator({ // 验证:模块名称
onshow: "(必填)",
onfocus: "(必填)不超过50个字符",
oncorrect: "(正确)"
}).inputValidator({
min: 1,
max: 50,
onerrormin: "(错误)不能为空",
onerrormax: "(错误)不超过50个字符,汉字算两个字符"
}).ajaxValidator({
type: "post",
url: "EnterpriseManage!ajaxValidatorUserAccount.action",
success: function (data) {
if (data == "0") {
return true;
} else if (data == "1") {
return false;
}
},
onerror: "该账号已被占用,请更换!"
}); //密码及重复密码验证
$("#password").formValidator({ // 验证:模块名称
onshow: "(必填)",
onfocus: "(必填)不超过11个字符",
oncorrect: "(正确)"
}).inputValidator({
min: 1,
max: 50,
onerrormin: "(错误)不能为空",
onerrormax: "(错误)不超过11个字符,汉字算两个字符"
}); $("#passwordRepeat").formValidator({
onshow: "(必填)",
onfocus: "(必填)2次密码必须一致",
oncorrect: "(正确)"
}).compareValidator({
desid: "password",
operateor: "=",
onerror: "(错误)2次密码不一致,请确认"
}); //图片格式验证
$("#tcCodeLogo").formValidator({
onshow: "(选填)",
onfocus: "(选填)请上传图片文件",
oncorrect: "(正确)",
empty: true
}).regexValidator({
regexp: regexEnum.picture,
onerror: "只能上传图片文件"
}); //数值验证
$("#nameNum").formValidator({ // 验证:模块名称
onshow: "(必填)",
onfocus: "(必填)值1到50",
oncorrect: "(正确)"
}).inputValidator({
min: 1,
max: 50,
type: "value",
onerrormin: "(错误)不能为空",
onerrormax: "(错误)值1到50"
});
//电话验证
$("#linkPhone").formValidator({
onshow: "(选填)",
onfocus: "(选填)",
oncorrect: "(正确)",
empty: true
}).regexValidator({
regexp: "^(\\d{3,4}-?\\d{7,8}|(13|15|18)\\d{9})$",
onerror: "(错误)电话号码格式不正确,请检查"
}); //EMail验证
$("#linkEmail").formValidator({
onshow: "(选填)",
onfocus: "(选填)请选择正确EMail格式",
oncorrect: "(正确)",
empty: true
}).regexValidator({
regexp: regexEnum.email,
onerror: "(错误)Email格式不正确,请检查"
}); //select验证
$("#testSelect").formValidator({
onshow: "(必填)",
onfocus: "(必填)请选择选项",
oncorrect: "(正确)"
}).inputValidator({
min: 0, //开始索引
onerror: "你是不是忘记选择学历了!"
}); //隐藏时,默认验证通过
$("#smsProductName").formValidator({ // 验证
onshow: "(必填)",
onfocus: "(必填)不超过50个字符,汉字算两个字符",
oncorrect: "(正确)"
}).functionValidator({
fun: function (val, elem) {
if ($("#smsProductName").is(":hidden")) {
return true;
}
if (!/^\S{1,50}$/.test(val)) {
return "(错误)不超过50个字符,汉字算两个字符";
}
return true;
}
});
//多选选择框的验证方式 略有点复杂了
$(":checkbox[name='productType']").formValidator({
onshow: "(至少选择一个)",
onfocus: "(至少选择一个)",
oncorrect: "(正确)"
}).functionValidator({
fun: function (val, elem) {
var objs = $(":checkbox[name='productType']");
for (var i = 0; i < objs.length; i++) {
if ($(objs[i]).attr("checked") == true) {
$('#productTypeTip').removeClass();
$('#productTypeTip').addClass("onSuccess");
$('#productTypeTip').html();
$('#productTypeTip').html("<nobr>正确</nobr>");
return true;
}
}
$('#productTypeTip').removeClass();
$('#productTypeTip').addClass("onError");
$('#productTypeTip').html();
$('#productTypeTip').html("<nobr>(至少选择一项)</nobr>");
return false;
}
});
} catch (e) {
alert(e);
}
});

  

formValidator的一些验证实例的更多相关文章

  1. formValidator输入验证、异步验证实例 + licenseImage验证码插件实例应用

    实例技术:springmvc 实现功能:完整用户登录流程.输入信息规则校验.验证码异步校验. 功能清单: 1.springmvc控制器处理get请求(/member/login.html),进行静态页 ...

  2. jQuery formValidator表单验证插件

    什么是jQuery formValidator? jQuery formValidator表单验证插件是客户端表单验证插件. 在做B/S开发的时候,我们经常涉及到很多表单验证,例如新用户注册,填写个人 ...

  3. (实用篇)php通过会话控制实现身份验证实例

    会话控制的思想就是指能够在网站中根据一个会话跟踪用户.这里整理了详细的代码,有需要的小伙伴可以参考下. 概述 http 协议是无状态的,对于每个请求,服务端无法区分用户.PHP 会话控制就是给了用户一 ...

  4. jQuery 验证实例(shopnc二次开发)

    shopnc 商家用户实现添加用户与前台用户分离, jQuery 验证实例 equalTo:等于 <div id="saleRefund" show_id="1&q ...

  5. 未找到或无法访问服务器 请验证实例名称是否正确并且SQL Server 已配置为允许远程连接

    无法连接到sql server 2008服务器 报下错误 其他信息    在与SQL Server建立连接时出现与网络相关的或特定于实例的错误 未找到或无法访问服务器请验证实例名称是否正确并且SQL ...

  6. 请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)

    程序异常,错误信息:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (pro ...

  7. Bootstrap+PHP表单验证实例

    简单实用的Bootstrap+PHP表单验证实例,非常适合初学者及js不熟悉者,还有ajax远程验证 js验证表单 1 $(document).ready(function() { 2 $('#def ...

  8. jQuery-easyui和validate表单验证实例

    jQuery EasyUI 表单 - 表单验证插件validatebox 使用时需要向页面引入两个css文件如下: <link rel="stylesheet" href=& ...

  9. Cookie && Session之验证实例

    为了防止各种自动登录,以及反作弊和破坏,往往会要求登录时让用户输入随机产生的验证码(这组验证码是一组数字和字母),这样可以起到一定的防止他人利用程序让机器自动反复登录的情况.在PHP下要实现这种功能是 ...

随机推荐

  1. POJ 3678 Katu Puzzle(强连通 法)

    题目链接 题意:给出a, b, c 和操作类型 (与或异或),问是否满足所有的式子 主要是建图: 对于 and , c == 1: 说明 a 和 b都是1,那么 0 就不能取, a' -> a ...

  2. 真机调试之android手机+chrome

    真机调试之android手机+chrome 虽然chrome上的移动设备模拟器很强大,但是在真机运行的时候,总会遇到一些小问题,这时就需要使用真机调试了. 第一步:准备一台android手机,并在手机 ...

  3. python regrex

    Python正则表达式指南 The source from the website http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.htm ...

  4. RAL 标准颜色表(RAL Color Chart)

    根据经典RAL系统,本网页显示RAL标准颜色的概览.RAL用于信息,为图画和涂层定义标准颜色.现在,它是最流行的中欧颜色标准.这些颜色广泛用于建筑学,建筑物,工业和道路安全. 图表中的RAL颜色尽可能 ...

  5. Windows系统自带工具的 cmd 命令

    目标 与计算机高手无关,只是为了减少鼠标点击的次数,提高效率. 适用范围 Windows XP,Windows 7,Window 8 (在Windows 7 下验证通过.) 使用方法 在 “运行“ 对 ...

  6. 签名有元程序集 Signed Friend Assemblies

    下面的例子演示了创建签名程序集和有元程序集.这就要求两个程序集都是强命名,在下面的例子中,两个程序集都用了同一个秘钥,也可以用不同的秘钥. 1. 生成秘钥, 这个在前面的博客中有说明,生成秘钥文件sn ...

  7. IBatis一对多查询

    public class User { public int UserId { get; set; } public string UserName { get; set; } } public cl ...

  8. 记一次mysql故障恢复

    事情要从俩月前的一个坑说起,一台新的测试服务器,新项目一元夺宝用的. 配置aws上的一台云主机,系统盘8G,一块300G的云硬盘. 拿到机器后,另一运维小哥安装php,nginx,mysql等软件. ...

  9. JavaWeb学习笔记——JavaEE基础知识

  10. JStorm集群的安装和使用

    0 JStorm概述 JStorm是一个分布式的实时计算引擎.从应用的角度,JStorm应用是一种遵守某种编程规范的分布式应用:从系统角度, JStorm是一套类似MapReduce的调度系统: 从数 ...