Skip to main content
Known Participant
June 15, 2017
Answered

Can javascript detect commas in path folder?

  • June 15, 2017
  • 3 replies
  • 731 views

Hi,

How can we make it so javascript detects whether user's path folder contains commas in it?  My program does not save to the path folder when the user has included commas in the folder name so I want to prevent this by generating an error when there are commas in the path folder.

Does it have something to do with what is in the following code?  In particular, is it saying the pathfolder cannot contain commas and to replace them?  If not, what does the text in red mean?

         var cSavePath = oOrigDoc.path.replace(/\/[^\/]+$/,"/");

Thanks.

S

This topic has been closed for replies.
Correct answer try67

Do you want to remove the commas, or just detect them?

If the former then you can't use it on the full path because if a folder name contains a comma and you remove it, the file can't be saved into that non-existing folder.

If the latter then you should use the test method, not the replace method. It would be something like this:

if (/,/.test(this.path)) app.alert("Invalid file-path. Please remove all commas.");

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 15, 2017

Do you want to remove the commas, or just detect them?

If the former then you can't use it on the full path because if a folder name contains a comma and you remove it, the file can't be saved into that non-existing folder.

If the latter then you should use the test method, not the replace method. It would be something like this:

if (/,/.test(this.path)) app.alert("Invalid file-path. Please remove all commas.");

suemo22Author
Known Participant
June 16, 2017

Wow, that worked!!!  Thx much!!!

Legend
June 15, 2017

You can use app.alert to see what cSavePath contains after this.

Bernd Alheit
Community Expert
Community Expert
June 15, 2017

The regular expression removes the document name.

suemo22Author
Known Participant
June 16, 2017

Ohhh, I see.  TY.