Bug fix: validate uploaded filename if contain special char
Budget: $12 – $30 SGD
validate only if user submit a web form. Noted that it is a multi row table which is has its own filename_x,where x is table counter.
following is my code but it doesn't take effect. need your help to debug and fix it. Need remotely resolve the issue. I believe my code not far from solution.
//in js
function specialCharCheck(str){
var specialCharactersString = "!@#$%&*()'+,-/:;<=>?[]^`{|}";
for(i=0;i<str.length;i++){
var charstr = str.charAt(i);
if (specialCharactersString.includes(str)){
break;
return true;
}
}
return false;
}
//in jsp part of code
if(!check_empty(form.elements['filename_'+i].value)){
var filenameValue = form.elements['filename_'+i].value;
if(specialCharCheck(filenameValue)){
alert("The attachments filaneme "+ i +" contain invalid character,please rename it then retry again");
form.elements['filename_'+i].className="man err";
form.elements['filename_'+i].focus();
return false;
}
}
following is my code but it doesn't take effect. need your help to debug and fix it. Need remotely resolve the issue. I believe my code not far from solution.
//in js
function specialCharCheck(str){
var specialCharactersString = "!@#$%&*()'+,-/:;<=>?[]^`{|}";
for(i=0;i<str.length;i++){
var charstr = str.charAt(i);
if (specialCharactersString.includes(str)){
break;
return true;
}
}
return false;
}
//in jsp part of code
if(!check_empty(form.elements['filename_'+i].value)){
var filenameValue = form.elements['filename_'+i].value;
if(specialCharCheck(filenameValue)){
alert("The attachments filaneme "+ i +" contain invalid character,please rename it then retry again");
form.elements['filename_'+i].className="man err";
form.elements['filename_'+i].focus();
return false;
}
}