3 Replies Latest reply: Mar 25, 2014 8:51 AM by TexasApexDeveloper RSS

    Restict the attachments file type to be limited pdf,gif,jpeg,doc,docx,xls,xlsx .

    Vedant

      Dear Friends,

       

      I have created document attchemnt interface .Now i need to attach file only type of pdf,gif,jpeg,doc,docx,xls,xlsx .

       

      How to validate attchmnet with these type of file.

       

       

      Thanks

        • 2. Re: Restict the attachments file type to be limited pdf,gif,jpeg,doc,docx,xls,xlsx .
          Bhramar

          Hi Vedant,

           

          Create a Page Level Validation  of Type - Regular Expression against your File Browse Item.

           

          Validation Expression 1 :   P1_FILE (assuming your item name to be P1_FILE)

          Validation Expression 2 :   ^.+\.((pdf)|(gif)|(jpeg)|(doc)|(docx)|(xls)|(xlsx))$

           

          Give the proper condition you want.

          • 3. Re: Restict the attachments file type to be limited pdf,gif,jpeg,doc,docx,xls,xlsx .
            TexasApexDeveloper

            A better way I have found, so that the user can NOT upload the file at all is to add the following javascript to the Javascript, Function and global variable declaration section of the page header

             

            function fileCheck(el){

                if(el.value){

                    var validFile = false;

                    var validExtensions = ["pdf"];

                    var filename = el.value;

                    var fileExtIndex = filename.lastIndexOf(".");

                    var fileExt = filename.substring(fileExtIndex+1, filename.length);

             

                    for(i = 0; i < validExtensions.length; i++){

                        if(validExtensions[i] == fileExt){

                            validFile = true;

                            break;

                        }

                    }

             

                    if ( !validFile || fileExtIndex == -1) {

                        alert("Invalid Extension. Permitted files must end with: " + validExtensions.toString());

                        var htmlContents = el.outerHTML || new XMLSerializer().serializeToString(el);

                        $('#P16_BINARY').replaceWith(htmlContents);

                    }

                }

             

            }

            On this line:  var validExtensions = ["pdf"] change this to hold the valid file Extensions..

             

            On your file upload control, in the html form element attributes add this code: onchange="fileCheck(this)"

             

            Thank you,

             

            Tony Miller
            LuvMuffin Software
            Ruckersville, VA

             

             

                ];