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

    Filter out certain characters and give error message

    I'm using the following 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;
    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:
    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