jquery input file validation -


i have validate input file have problem when rules work required rules , not accept rules , filesize rules, here code

$('#myform').validate({     rules: { image: { required: true, accept: "bmp", filesize: 1048576  }},     messages: { image:{ required: "insert image", accept: "must in jpg,png , bimp format", filesize: "less 1mb"  }} }); 

when dont insert image validation work, message error occurs, when insert image not in bmp format or image size more 1mb validation not work

please me..

thanks..

you can add validation method that

$.validator.addmethod("uploadfile", function (val, element) {     var ext = $(element).val().split('.').pop().tolowercase();     var allow = new array('bmp');     var size = element.files[0].size;      if (jquery.inarray(ext, allow) == -1 || size > 1048576) {         return false     } else {         return true     }  }, "invalid file"); 

and use -

rules: {     image: {        required: true,        uploadfile:true     } } 

demo --> http://jsfiddle.net/pendy/2/


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -