当我上传Image时,验证工作正常但是当我
时更新图像我要验证输入类型文件是否为空。如何检查
它?
实际上我想在Update期间使用相同的验证功能来上传图像(创建图像)?
我该怎么做?验证功能如下: - >
var teacherValidation = function() {
// for more info visit the official plugin documentation:
// http://docs.jquery.com/Plugins/Validation
var form1 = $('#form_teacher');
var error1 = $('.alert-danger', form1);
var success1 = $('.alert-success', form1);
form1.validate({
errorElement: 'span', //default input error message container
errorClass: 'help-block help-block-error', // default input error message class
focusInvalid: false, // do not focus the last invalid input
ignore: "", // validate all fields including form hidden input
messages: {
select_multi: {
maxlength: jQuery.validator.format("Max {0} items allowed for selection"),
minlength: jQuery.validator.format("At least {0} items must be selected")
}
},
rules: {
fileData: {
required: true
}
},
submitHandler: function (form) {
success1.show();
error1.hide();
form.submit();
}
});
}
答案 0 :(得分:0)
在您的情况下,您可以使用自己的自定义功能来验证首次上传和更新时间所需的文件
$(document).ready(function(){
jQuery.validator.addMethod("filetype", function(value, element) {
var types = ['jpeg', 'jpg', 'png'],
ext = value.replace(/.*[.]/, '').toLowerCase();
if (types.indexOf(ext) !== -1) {
return true;
}
return false;
},"Please select allowed file");
$('#frm').validate({
rules:
{
file:
{
filetype: true
}
}
});
});