Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    DKY
    DKY is offline
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filter out certain characters and give error message

    I'm using the following code

    Code:
    <script type="text/javascript">
    
    function checkField() {   
    
     var filebox = document.getElementById("File");   
    
     var regex = /\W/;   
    
     if (filebox.value.match(regex)) {      
    
      alert('Selected File Contains Invalid Characters!');      
    
      return false;   
    
     }
    
    } 
    
    window.onload = function () {   
    
     document.getElementById("File").onchange = checkField;   
    
     document.forms[0].onsubmit = checkField;
    
    }
    
    </script>
    to try and prevent users from uploading files in an <input type="file"> that have characters that are not conducive to downloading. The problem I'm finding is that the code above seems to look at the whole path that is in the input box as opposed to just the file name. I know absolutely nothing about javascript, does anyone know how I can manipulate this code to have it just look at the file name?



    I've also posted this question at the following links:
    http://forums.devshed.com/javascript...ml#post2196276
    http://www.sitepoint.com/forums/show...74#post4127674
    http://www.webdeveloper.com/forum/sh...836#post972836
    Last edited by DKY; 01-27-2009 at 02:36 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •