validate表单校验添加自己的验证方法

validate表单校验添加自己的验证方法

多手机号验证

			//多手机号验证
            jQuery.validator.addMethod("isPhones",function(value,element){
                value = value.replace(",", ",");
                var phonesarr=value.split(",");
                for (var i=0;i<phonesarr.length;i++) {
                    var phonei = phonesarr[i];
                    var length = phonei.length;
                    var phone=/^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
                    var isphone = this.optional(element)||(length == 11 && phone.test(phonei));
                    if (length == 0) {
                        return true;
                    }else if(!isphone){
                        return false;
                    }
                }
                return true;
            },"请填写正确的11位手机号,用英文逗号隔开");

三选一 填写其中一个则验证通过

            //三选一
            jQuery.validator.addMethod("eitheror",function(value,element){
                var name = $('#name').val();
                var phones = $('#phones').val();
                var imPhones = $('#importPhones').val();
                var nameb = name == undefined || name.length <=0;
                var phonesb = phones == undefined || phones.length <=0;
                var imPhonesb = imPhones == undefined || imPhones.length <=0;
                return !rynameb || !phonesb || !imPhonesb;
            },"请选择人员或输入手机号");

你可能感兴趣的:(jquery)