jquery.validate 客户端验证“必填”“URL”“最小最小长度”“最大最小值”“数字”“身份证”“信用卡”“邮编”等

Jquery.validata 使用

添加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

验证邮政编码

 

demo我上传了,还没给我通过审核,通过了我再给链接,要不直接到我的资源找去也行。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值