I am trying to clean up a validation script.
So if the file type uploaded is wrong -- like an image instead of a pdf. I need the alert to say -- Wrong file type uploaded, only pdf accepted.
https://jsfiddle.net/mf78otve/37/
so the validation string looks like this
"application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf"
but really need to clean it up -- pdf, x-pdf, vnd.pdf, pdf, x-pdf
then remove duplicates to then pdf, x-pdf, vnd.pdf
var validations = "application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf";
console.log("validations", validations);
var res = validations.split("/");
console.log("res", res);
var uniqueArray = function(arrArg) {
return arrArg.filter(function(elem, pos,arr) {
return arr.indexOf(elem) == pos;
});
};
console.log(uniqueArray(res));
Aucun commentaire:
Enregistrer un commentaire