Created
August 9, 2013 02:05
-
-
Save Gwash3189/6190598 to your computer and use it in GitHub Desktop.
Validating File Extensions with JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks through a list of fileURI's and compares the | |
* file extensions of those fileURI's to the acceptedPhotoTypes | |
* @param files array of objects with a source property, this property is the fileURI location of the photo | |
* @param acceptedTypes an array of accepted photo types. EG '.jpeg' | |
* @returns {boolean} | |
*/ | |
function validateFileExtensions(files, acceptedTypes) { | |
var passed = false; | |
/** | |
* Checks a single file URI for the existance of a | |
* accepted file extension | |
* @param fileUri | |
* @returns {boolean} | |
*/ | |
function checkFileUri(fileUri) { | |
for (var i = 0; i < acceptedTypes.length; i++) { | |
if (fileUri.indexOf(acceptedTypes[i]) > -1) { | |
passed = true | |
} | |
} | |
return passed; | |
} | |
for (var i = 0; i < files.length; i++) { | |
passed = checkFileUri(files[i].source); | |
} | |
return passed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment