Often you are relying on users to enter valid text for element names, file names, folders, etc. There is no "isValidFolderName()" function attached to the FileSystemObject, and even if there were, it would be useless because this status changes with each new Windows version (for example, I can currently name a folder with a comma in it, but Server.MapPath can't handle it).
The following technique will show you how you can easily adjust one line of code to prevent any of a list of characters from appearing in a string.
<% ' here is the element name you want to check ' this can come from request.form or querystring elementName = "foobar" ' control variable invalcount = 0 ' set up a list of unacceptable characters ' this includes spaces, dashes and underscores ' you can leave these out of the list ' you may need to add other characters, e.g. copied from MSWord invalidList = ",<.>?;:'@#~]}[{=+)(*&^%$£!`¬| -_" ' check for " which can't be inside the string if instr(elementName,chr(34))>0 then invalcount = 1 else ' loop through, making sure no characters ' are in the 'reserved characters' list for i = 1 to len(invalidList) if instr(elementName,mid(invalidList,i,1))>0 then invalcount = 1 exit for end if next end if if invalcount > 0 then response.write "bad elementName." else response.write "good elementName." end if %> |