[英]jquery input type file validation
This is my html form. 这是我的html表格。 It contains jquery validation plugin.
它包含jquery验证插件。 I am trying to validate my input field type file.
我正在尝试验证我的输入字段类型文件。 When i will submit the form it should check user upload image or not.
当我提交表单时,应该检查用户上传的图像与否。
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo $this->config->base_url(); ?>r/js/jquery.validate.js"></script>
<script type="text/javascript" src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
</head>
<body>
<form role="form" name="add_app_form">
<div class="upload-app-icon">
<span>Uplod your App icon here</span>
<div class="add-icon"><input type="file" name="app_icon" id="app_icon" ></div>
</div>
<div class="submit-formbtn">
<input class="icon-btn" type="submit" value="Upload">
</div>
</form>
When i submit my form jquery validation doesn't work. 当我提交表单时,jQuery验证不起作用。 I am using this javascript but it is not working
我正在使用此javascript,但无法正常工作
<script type="text/javascript">
$.validator.addMethod("notEqual", function(value, element, param) {
return this.optional(element) || value != param;
});
$("#add_app_form").validate({
rules: {
app_icon:{
required: true,
extension: "xls|csv"
}
},
messages: {
app_icon: "Add icon"
},
tooltip_options: {
app_icon: {placement:'top',html:true}
}
});
</script>
Limit file types on the element itself using accept attribute for the 99.9% of use cases. 在99.9%的用例中,使用accept属性限制元素本身上的文件类型。 http://www.w3schools.com/tags/att_input_accept.asp
http://www.w3schools.com/tags/att_input_accept.asp
However, as it points out, don't use this for validation/security purposes. 但是,正如指出的那样,请勿将其用于验证/安全性目的。 All file type/content validation should be done on the server side.
所有文件类型/内容验证应在服务器端进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.