File Type Validation using Java Script

Introduction

File type validation before uploading to the server is mandatory for every file upload in the web application. It helps to ensure that the user has selected the correct types of file to upload. Client side validation is more user-friendly than server side. It will be a good idea to validate file type before submitting to upload. Using JavaScript, you can easily check the selected file extension with allowed file extensions.

Steps to follow

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;

}}

  

Call To Action:

For Oracle apex development and customization please do visit our company website https://doyensys.com/

 

Conclusion

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

 

Recent Posts