一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jquery表单验证插件用法与实例

时间:2010-08-17 编辑:简简单单 来源:一聚教程网






   

       
ps教程kyblue thin solid; display:none; margin:0; padding:0; border-top: deepskyblue thin solid;
            border-left: deepskyblue thin solid; color: #3300ff; border-bottom: deepskyblue thin solid;
            ">
       

       
           
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
       

                    jion to us

                    username: 

       

                    password:

       

                    and once again? 
                   

               

                   

                    and your sex?

                   
                    男
                   
                    女

                    your telephone:

                   

                    your email:

                   

                    your age:

                   

                    your weight:

                   

                    country:

       
               

                    remark:

       

               

        i agree all the terms.

               

       

   

   


 规则说明:required:true 必填
                   minlength:最小长度
                   maxlength:最大长度
                   rangelength: [3,10] 长度介于 3 和 {1} 之间的字符串
                   range:[100,1000] 只能是100和 1000 之间的值"
                   min:最小值
                   max:最大值
                   email:true  验证邮箱
                   url:true 验证是否是合法的网址
                   date:true 验证是否是合法的日期 new date() 类型格式
                   dateiso:true 验证是否是合法的日期 年/月/日 或 年-月-日 格式
                   number:true 验证是否是合法的数字
                   digits:true 验证是否为整数
                   creditcard: 验证合法的信用卡号
                   equalto:"要匹配的元素" 如:'#cnfpass' ,  验证两次输入值是否相同
                   accept: "gif|png|jpg"  验证是否是合法后缀名的字符串
                   remote:'url'  远程验证输入的值是否合法 url是返回true验证成功,false验证失败
          这些是插件中提供的验证规则,插件中还提供了增加规则的方法,可以来增加一些我们自己规则,方法如:
jquery.validator.addmethod("规则名称", function(value, element, params) {   return this.optional(element) || 验证value   }
         b)使用jquery.validate的validate方法来验证
 


下面来看一下jquery  checkform插件简单用法
 

$(function(){

    $("form").valid([

    //验证选择

    { name:"checkbox",simple:"多选" },

    //验证必填,只要不为空

    { name:"username",simple:"用户名" },

    //非必填,邮箱类型

    { name:"email",type:"mail",simple:"邮箱",require:false }

    ]);

 

 })


热门栏目