File Type Validation using Java Script

Step 1:
Create
a File browse item.
Step 2:
Create
a button to submit the page. Give the Action when Clicked as Defined by Dynamic
Action.
Step 3:
Create
a Dynamic Action with execution of JavaScript as
function
validateEstimation() {
            var IsValid = true;
    var
estimate_file=$(“#P13_ESTIMATE_FILE”).val().trim();
       
            if (IsValid) {
              var exist_file= “”;
            if($(“#P13_DOWNLOAD_FILE”).length
> 0) exist_file = $(“#P13_DOWNLOAD_FILE”).html();
               if (estimate_file == “”
&& exist_file == “”) {
                                                            IsValid
= false;
                    alert(“Please select
estimate file.”);
               }
               else if (estimate_file
!=””)
               {
                   estimate_file = estimate_file.substring(estimate_file.lastIndexOf(“.”));
                   //alert(estimate_file);
                   var allowedFormats =
“|.pdf|.xls|.doc|.xlsx|.docx|”;
                   if
(allowedFormats.indexOf(“|” + estimate_file + “|”) == -1) {
                       IsValid = false;
                       alert(“Invalid
Estimate file format selected.”);
$(“#P13_ESTIMATE_FILE”).val(”);
                   }
               }
                   if (!IsValid) return false;
            }
}

This
Java Script function helps to accept .pdf,.xls,.doc,.xlsx,.docx files.

By
A.Arun Kumar
  • December 29, 2016 | 14 views
  • Comments