Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-27-2009, 01:34 AM   PM User | #1
DKY
New Coder

 
Join Date: Jan 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
DKY is an unknown quantity at this point
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 01:36 AM..
DKY is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:19 AM.


Advertisement
Log in to turn off these ads.