...

View Full Version : Filter out certain characters and give error message



DKY
01-27-2009, 01:34 AM
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;

}

</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-development-115/filter-out-certain-characters-and-give-error-message-586186.html#post2196276
http://www.sitepoint.com/forums/showthread.php?p=4127674#post4127674
http://www.webdeveloper.com/forum/showthread.php?p=972836#post972836



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum