Hi there
Ideally, I'd like to create one javascript function and pass the file
extension i'm looking for to see if its there:
<input type="file" onchange="checkFile('pdf',this)" />
and then have the function something like (w/ Prototype)
function checkFile(theExtension,theField) {
var field = $(theField);
var fieldName = field.name;
var fieldID = field.id;
var fieldValue = field.value;
var matchPattern = "/\."+theExtension+"$/im";
if (fieldValue.match(matchPattern)) {
alert('Its a '+theExtension+'!');
} else {
alert('no!');
}
}
The problem is, the line with "fieldValue.match" is not using the "var
matchPattern" value (my RegEx expression)...
Can anyone make this work / must i use 'eval' to get the match to work
against the dynamic var I created?