title: How to use Regular expression to test for FIle Names with special characters
body: <p>I am trying to use this open source image uploader: <a href="https://github.com/blueimp" rel="nofollow">https://github.com/blueimp</a> </p>
  
  <p>The documentation says that the function to match on File Type can be used to match on file name also. </p>
  
  <p><a href="https://github.com/blueimp/jQuery-File-Upload/blob/7d46990486ff08acfc001b6368b09bce6712c2c2/js/jquery.fileupload-validate.js" rel="nofollow">https://github.com/blueimp/jQuery-File-Upload/blob/7d46990486ff08acfc001b6368b09bce6712c2c2/js/jquery.fileupload-validate.js</a></p>
  
  <p>Can anyone see a way to use this to match on and restrict special characters in the file names? </p>
  
  <p>Here is the RegEx that will match the characters that I specifically want to exclude. I am trying to prevent end users from using special characters in file names, instead of just depending on training them.  English is the only concern in this case. </p>
  
  <pre><code>[&amp;~@#$^*()_+=/:?;\\|&lt;&gt;"',!%]
  </code></pre>
  
  <p>Here is the snipit from the source code (open source) that would evaluate it. Full code available at the link above.</p>
  
  <pre><code> // The File Upload Validation plugin extends the fileupload widget
  // with file validation functionality:
  $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  
      options: {
          /*
          // The regular expression for allowed file types, matches
          // against either file type or file name:
          acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
          // The maximum allowed file size in bytes:
          maxFileSize: 10000000, // 10 MB
          // The minimum allowed file size in bytes:
          minFileSize: undefined, // No minimal file size
          // The limit of files to be uploaded:
          maxNumberOfFiles: 10,
          */
  
          // Function returning the current number of files,
          // has to be overriden for maxNumberOfFiles validation:
          getNumberOfFiles: $.noop,
  
          // Error and info messages:
          messages: {
              maxNumberOfFiles: 'Maximum number of files exceeded',
              acceptFileTypes: 'File type not allowed',
              maxFileSize: 'File is too large',
              minFileSize: 'File is too small'
          }
      },
  
      processActions: {
  
          validate: function (data, options) {
              if (options.disabled) {
                  return data;
              }
              var dfd = $.Deferred(),
                  settings = this.options,
                  file = data.files[data.index],
                  fileSize;
              if (options.minFileSize || options.maxFileSize) {
                  fileSize = file.size;
              }
              if ($.type(options.maxNumberOfFiles) === 'number' &amp;&amp;
                      (settings.getNumberOfFiles() || 0) + data.files.length &gt;
                          options.maxNumberOfFiles) {
                  file.error = settings.i18n('maxNumberOfFiles');
              } else if (options.acceptFileTypes &amp;&amp;
                      !(options.acceptFileTypes.test(file.type) ||
                      options.acceptFileTypes.test(file.name))) {
                  file.error = settings.i18n('acceptFileTypes');
              } else if (fileSize &gt; options.maxFileSize) {
                  file.error = settings.i18n('maxFileSize');
              } else if ($.type(fileSize) === 'number' &amp;&amp;
                      fileSize &lt; options.minFileSize) {
                  file.error = settings.i18n('minFileSize');
              } else {
                  delete file.error;
              }
              if (file.error || data.files.error) {
                  data.files.error = true;
                  dfd.rejectWith(this, [data]);
              } else {
                  dfd.resolveWith(this, [data]);
              }
              return dfd.promise();
          }
  
      }
  
  });
  </code></pre>
  
  <p>Edit: Some things I have tried:</p>
  
  <p>Thanks for the quick responses. Some things I have tried here:
  Many of these return the the match even it it the name is preceeded by an invalid character. 
  See <a href="http://regexr.com/3be9o" rel="nofollow">http://regexr.com/3be9o</a>
  I don't want asdf&amp;ghjik.jpg to match as valid.</p>
  
  <p>I guess I really want a-z A-Z 0-9 - _</p>
  
  <pre><code>[^&amp;~@#$^*()_+=/:?;\\|&lt;&gt;"',!%]([\w]+\-*[\w]+)+(\.|\/)(gif|jpe?g|png)
  
  ([^&amp;~@#$^*()_+=/:?;\\|&lt;&gt;"',!%])?([\w]+\-*[\w]+)+(\.|\/)(gif|jpe?g|png)
  
  ([\w]+\-+[\w]+)+(\.|\/)(gif|jpe?g|png)
  
  [^&amp;~@#$^*()_+=/:?;\\|&lt;&gt;"',!%]*(\.jpg)|[^&amp;~@#$^*()_+=/:?;\\|&lt;&gt;"',!%]*(\.png)|
  
  [^&amp;~@#$^*()_+=/:?;\\|&lt;&gt;"',!%]*(\.gif)|[^&amp;~@#$^*()_+=/:?;\\|&lt;&gt;"',!%]*(\.jpeg)
  </code></pre>