jquery.validate 客户端验证“必填”“URL”“最小最小长度”“最大最小值”“数字”“身份证”“信用卡”“邮编”等
2011-09-21 12:15
281 查看
Jquery.validata 使用
{
background:url(images/error.png) no-repeat 0px 0px;
color: Red;
padding-left: 20px;
}
注册验证的form
<script type="text/javascript">
$(function(){
jQuery("#<%=form1.ClientID %>").validate();
})
</script>
例子:
验证电话的:
<asp:TextBox ID="txtTel"runat="server" Style="width: 200px;"CssClass="{required:true,isPhone:true, messages:{required:'忘记输入电话了哦',isPhone:'电话号码不对哦'}}"></asp:TextBox>
详细使用,请浏览demo
demo我上传了,还没给我通过审核,通过了我再给链接,要不直接到我的资源找去也行。
添加js引用
添加jquery.js,jquery.validate1.js,jquery.metadata.js,jQuery.validate.message_cn.js,jquery.validate.ext.js文件的引用。注意顺序添加一个错误提示的样式(可定义自己喜欢的),
label.error{
background:url(images/error.png) no-repeat 0px 0px;
color: Red;
padding-left: 20px;
}
注册验证的form
<script type="text/javascript">
$(function(){
jQuery("#<%=form1.ClientID %>").validate();
})
</script>
使用方法
格式是json,注意绿色的地方例子:
验证电话的:
<asp:TextBox ID="txtTel"runat="server" Style="width: 200px;"CssClass="{required:true,isPhone:true, messages:{required:'忘记输入电话了哦',isPhone:'电话号码不对哦'}}"></asp:TextBox>
详细使用,请浏览demo
验证类型:
内置验证方式: | ||
required() | 返回:Boolean | 必填验证元素 |
required(dependency-expression) | 返回:Boolean | 必填元素依赖于表达式的结果 |
required(dependency-callback) | 返回:Boolean | 必填元素依赖于回调函数的结果 |
remote(url) | 返回:Boolean | 请求远程校验。url通常是一个远程调用方法 |
minlength(length) | 返回:Boolean | 设置最小长度 |
maxlength(length) | 返回:Boolean | 设置最大长度 |
rangelength(range) | 返回:Boolean | 设置一个长度范围[min,max] |
min(value) | 返回:Boolean | 设置最大值 |
max(value) | 返回:Boolean | 设置最小值 |
email() | 返回:Boolean | 验证电子邮箱格式 |
range(range) | 返回:Boolean | 设置值的范围 |
url() | 返回:Boolean | 验证URL格式 |
date() | 返回:Boolean | 验证日期格式(类似30/30/2008的格式,不验证日期准确性只验证格式) |
dateISO() | 返回:Boolean | 验证ISO类型的日期格式 |
dateDE() | 返回:Boolean | 验证德式的日期格式(29.04.1994 or 1.1.2006) |
number() | 返回:Boolean | 验证十进制数字(包括小数的) |
digits() | 返回:Boolean | 验证整数 |
creditcard() | 返回:Boolean | 验证信用卡号 |
accept(extension) | 返回:Boolean | 验证相同后缀名的字符串 |
equalTo(other) | 返回:Boolean | 验证两个输入框的内容是否相同 |
phoneUS() | 返回:Boolean | 验证美式的电话号码 |
扩展的验证方式:(如果不需要,可以不添加jquery.validate.ext.js文件) | ||
stringCheck() | 返回:Boolean | 只能包括中文字、英文字母、数字和下划线 |
isIdCardNo() | 返回:Boolean | 验证身份证号码 |
isMobile() | 返回:Boolean | 验证手机号码 |
isTel() | 返回:Boolean | 验证电话号码 |
isPhone() | 返回:Boolean | 验证联系电话(手机/电话皆可) |
isZipCode() | 返回:Boolean | 验证邮政编码 |
相关文章推荐
- 常用表单验证类,验证EMAIL地址,电话号码,指定长度数字,汉字,邮编,URL地址等
- 常用表单验证类,验证EMAIL地址,电话号码,指定长度数字,汉字,邮编,URL地址等2007-10-11 09:14
- jQuery.Validate进行客户端验证
- 验证 网址,IP,邮箱,电话,手机,数字,英文,日期,身份证,邮编
- 数据格试验证(Email,IP地址,URL地址,身份证,电话,日期,中文,字母数字组合,字符或是数字)
- C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编
- [轉]dwz-user-guide(Jquery 富客户端) + jQuery.validate(js验证)
- 使用jQuery.Validate进行客户端验证(初级篇) 不使用微软验证控件的理由
- C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编验证电话号码的主要代码如下:
- C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编
- [jQuery]使用jQuery.Validate进行客户端验证——不使用微软验证控件的理由-目录及简介
- C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编
- [jQuery]使用jQuery.Validate进行客户端验证(高级篇-下)——不使用微软验证控件的理由
- C# 验证邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,IP类
- 使用jQuery.Validate进行客户端验证
- C#验证类 可验证:邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,IP (转)
- (转)[jQuery]使用jQuery.Validate进行客户端验证(初级篇)——不使用微软验证控件的理由
- C#验证类 可验证:邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,IP
- jquery validate 身份证验证(可以为空)
- :验证 网址,IP,邮箱,电话,手机,数字,英文,日期,身份证,邮编,