Skip to content

Instantly share code, notes, and snippets.

@Gwash3189
Created August 9, 2013 02:05
Show Gist options
  • Save Gwash3189/6190598 to your computer and use it in GitHub Desktop.
Save Gwash3189/6190598 to your computer and use it in GitHub Desktop.
Validating File Extensions with JavaScript
/**
* 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