diff --git a/vendor/magento/module-media-gallery-ui/view/adminhtml/web/js/directory/directories.js b/vendor/magento/module-media-gallery-ui/view/adminhtml/web/js/directory/directories.js
index b3f62fc6673b6..b2feb246451b4 100644
--- a/vendor/magento/module-media-gallery-ui/view/adminhtml/web/js/directory/directories.js
+++ b/vendor/magento/module-media-gallery-ui/view/adminhtml/web/js/directory/directories.js
@@ -119,26 +119,26 @@ define([
           * Return configured prompt with input field
           */
         getPrompt: function (data) {
-                prompt({
-                    title: $t(data.title),
-                    content:  $t(data.content),
-                    modalClass: 'media-gallery-folder-prompt',
-                    validation: true,
-                    validationRules: ['required-entry', 'validate-filename'],
-                    attributesField: {
-                        name: 'folder_name',
-                        'data-validate': '{required:true, validate-filename}',
-                        maxlength: '128'
-                    },
-                    attributesForm: {
-                        novalidate: 'novalidate',
-                        action: ''
-                    },
-                    context: this,
-                    actions: data.actions,
-                    buttons: data.buttons
-                });
-            },
+            prompt({
+                title: $t(data.title),
+                content:  $t(data.content),
+                modalClass: 'media-gallery-folder-prompt',
+                validation: true,
+                validationRules: ['required-entry', 'validate-filename'],
+                attributesField: {
+                    name: 'folder_name',
+                    'data-validate': '{required:true, validate-filename}',
+                    maxlength: '128'
+                },
+                attributesForm: {
+                    novalidate: 'novalidate',
+                    action: ''
+                },
+                context: this,
+                actions: data.actions,
+                buttons: data.buttons
+            });
+        },
 
         /**
           * Confirmation popup for delete folder action.
@@ -186,11 +186,11 @@ define([
          * @param {String} folderId
          */
         setActive: function (folderId) {
+            this.selectedFolder(folderId);
+
             if (!this.allowedActions.includes('delete_folder')) {
                 return;
             }
-
-            this.selectedFolder(folderId);
             $(this.deleteButtonSelector).prop('disabled', false).removeClass('disabled');
         },
 
@@ -200,7 +200,7 @@ define([
         _addValidation: function () {
             $.validator.addMethod(
                 'validate-filename', function (value) {
-                    return $.mage.isEmptyNoTrim(value) || /^[a-z0-9\-\_]+$/si.test(value);
+                    return $.mage.isEmptyNoTrim(value) || /^[a-z0-9_-]+$/i.test(value);
                 },
                 $.mage.__('Please use only letters (a-z or A-Z), numbers (0-9), underscore (_) or hyphen (-) in this field. No spaces or other characters are allowed.')); //eslint-disable-line max-len
         }

