不使用bootstrap验证上传带.jpg扩展名的照片

时间:2014-09-05 06:33:41

标签: javascript jquery html5 twitter-bootstrap validation

我正在上传" .jpg"的照片扩展使用bootstrap验证,但不接受.jpg文件

检查我的FIDDLE

我甚至已经浏览过Bootstrap MIME类型..

我也尝试了各种选择,但没有成功..

验证选项1:

$(document).ready(function() {
    $('#uploadForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            avatar: {
                validators: {
                    file: {
                        extension: 'jpeg|jpg,png',
                        type: 'image/jpeg,image/png',
                        maxSize: 2048 * 1024,   // 2 MB
                        message: 'The selected file is not valid'
                    }
                }
            }
        }
    });
});

验证选项2:

$(document).ready(function() {
        $('#uploadForm').bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                avatar: {
                    validators: {
                        file: {
                            extension: 'jpeg jpg,png',
                            type: 'image/jpeg,image/png',
                            maxSize: 2048 * 1024,   // 2 MB
                            message: 'The selected file is not valid'
                        }
                    }
                }
            }
        });
    });

1 个答案:

答案 0 :(得分:1)

extension: 'jpeg|jpg,png',更改为extension: 'jpeg,jpg,png',

Demo