formValidator的一些验证实例
原帖地址: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的一些验证实例的更多相关文章
- formValidator输入验证、异步验证实例 + licenseImage验证码插件实例应用
实例技术:springmvc 实现功能:完整用户登录流程.输入信息规则校验.验证码异步校验. 功能清单: 1.springmvc控制器处理get请求(/member/login.html),进行静态页 ...
- jQuery formValidator表单验证插件
什么是jQuery formValidator? jQuery formValidator表单验证插件是客户端表单验证插件. 在做B/S开发的时候,我们经常涉及到很多表单验证,例如新用户注册,填写个人 ...
- (实用篇)php通过会话控制实现身份验证实例
会话控制的思想就是指能够在网站中根据一个会话跟踪用户.这里整理了详细的代码,有需要的小伙伴可以参考下. 概述 http 协议是无状态的,对于每个请求,服务端无法区分用户.PHP 会话控制就是给了用户一 ...
- jQuery 验证实例(shopnc二次开发)
shopnc 商家用户实现添加用户与前台用户分离, jQuery 验证实例 equalTo:等于 <div id="saleRefund" show_id="1&q ...
- 未找到或无法访问服务器 请验证实例名称是否正确并且SQL Server 已配置为允许远程连接
无法连接到sql server 2008服务器 报下错误 其他信息 在与SQL Server建立连接时出现与网络相关的或特定于实例的错误 未找到或无法访问服务器请验证实例名称是否正确并且SQL ...
- 请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)
程序异常,错误信息:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (pro ...
- Bootstrap+PHP表单验证实例
简单实用的Bootstrap+PHP表单验证实例,非常适合初学者及js不熟悉者,还有ajax远程验证 js验证表单 1 $(document).ready(function() { 2 $('#def ...
- jQuery-easyui和validate表单验证实例
jQuery EasyUI 表单 - 表单验证插件validatebox 使用时需要向页面引入两个css文件如下: <link rel="stylesheet" href=& ...
- Cookie && Session之验证实例
为了防止各种自动登录,以及反作弊和破坏,往往会要求登录时让用户输入随机产生的验证码(这组验证码是一组数字和字母),这样可以起到一定的防止他人利用程序让机器自动反复登录的情况.在PHP下要实现这种功能是 ...
随机推荐
- Python基本数据类型之tuple
一.创建元组: ages = (11, 22, 33, 44, 55) ages = tuple((11, 22, 33, 44, 55)) 元组和列表几乎一样 元组的元素不可修改,但是元组元素的元素 ...
- IOS VFL屏幕自适应
-(void)fun1{ //注意使用VFL,不用设置视图的frame UIView *view = [[UIView alloc] init]; view.backgroundColor = [UI ...
- Android之Proguard语法
-include {filename} 从给定的文件中读取配置参数 -basedirectory {directoryname} 指定基础目录为以后相对的档案名称 -injars {class_pat ...
- JavaWeb学习笔记——Ajax
- zepto.js之ajax剖析
1.ajax的baseHeaders ajax插件中的baseHeaders对象的是http请求头部的信息 var mime = settings.accepts[dataType], baseHea ...
- HBase命令(三) -- 增删改查
新增 //语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp> //新增或 ...
- Code First 关系 Fluent API
通过实体框架 Code First,可以使用您自己的域类表示 EF 执行查询.更改跟踪和更新函数所依赖的模型.Code First 利用称为“约定先于配置”的编程模式.这意味着 Code First ...
- Centos7安装rabbitmq server 3.6.0
###假设所有操作在opt目录下进行 cd /opt mkdir apps cd apps ### 下载 RabbitMQ Server wget http://www.rabbitmq.com/re ...
- mysql数据表分表策略2(转)
mysql分表方法: 方法一. 做数据库集群! 主从数据库 双向热备份(或一对多的数据库实时备份策略),这样可将数据库查询分摊到几个服务器去(可跟服务器负载均衡结合起来架构) 优点:扩展性好,没有多个 ...
- VS2015新建asp.net core站点
摘要 电脑上安装了vs2015,今天就尝尝鲜,新建一个项目试试. BBS 使用vs2015新建一个解决方案,然后新建项目,此时你会发现没有asp.net core项目,这就需要先安装asp.net c ...