Skip to content
Browse files

check for selected file names using regular expression

  • Loading branch information...
1 parent e020363 commit d7233cc23f4559cc05eae8b1f4ffb09dd65b077c @ruado1987 committed
Showing with 20 additions and 2 deletions.
  1. +20 −2 src/javascript/plupload.js
View
22 src/javascript/plupload.js
@@ -211,7 +211,14 @@
* @final
*/
FILE_EXTENSION_ERROR : -601,
-
+ /**
+ * File name error. If the user selects a file that isn't valid according to the name regular expression
+ *
+ *@property FILE_NAME_ERROR
+ *@final
+ */
+ FILE_NAME_ERROR: -602,
+
/**
* Runtime will try to detect if image is proper one. Otherwise will throw this error.
*
@@ -1057,7 +1064,7 @@
// Add files to queue
self.bind('FilesAdded', function(up, selected_files) {
- var i, file, count = 0, extensionsRegExp, filters = settings.filters;
+ var i, file, count = 0, extensionsRegExp, filters = settings.filters, name_regex = settings.file_name_pattern;
// Convert extensions to regexp
if (filters && filters.length) {
@@ -1104,6 +1111,17 @@
continue;
}
+ // Invalid file name
+ if(name_regex && !name_regex.test(file.name)) {
+ up.trigger('Error', {
+ code: plupload.FILE_NAME_ERROR,
+ message: 'File name error.',
+ file: file
+ });
+
+ continue;
+ }
+
// Add valid file to list
files.push(file);
count++;

0 comments on commit d7233cc

Please sign in to comment.
Something went wrong with that request. Please try again.