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

01-27-2009, 02: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;



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: