jQuery.validate的accept 验证失败
其它验证都对,像required,maxlenth等 ,但是accept验证不对。不知为什么。
谢谢大牛!
<input name="upload" class="input-file" type="file"/>
JS代码:
$("#uploadForm").validate(
{
rules:{
upload:{
required:true,accept:'zip'
}
},
messages:{
upload:{
required:'请选择文件!',
accept:'上传的文件格式不正确!',
}
},
submitHandler:function(form){
form.submit();
}
}
)
------解决方案--------------------accept接受的是mime-type
你应该改用 extension:"zip"
------解决方案--------------------参考http://jqueryvalidation.org/documentation/
------解决方案--------------------<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
// just for the demos, zip form submit
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#myform" ).validate({
rules: {
field: {
required: true,
accept: "zip/*"
}
}
});
</script>
</body>
------解决方案--------------------upload:{
required:true,
extension:'zip'
}