By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Folder location validation

P: n/a
guys,

how do i check if the folder location the user is entering ends with a
\. and if it does not show and error and if does end with a \ process
the form.

thanks.

Sep 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
pe******@gmail.com wrote:
guys,

how do i check if the folder location the user is entering ends with a
\. and if it does not show and error and if does end with a \ process
the form.
<input type="text" onblur="alert(/\\$/.test(this.value));">

Can you guarantee that the directory path *must* end with a "\"
character? In UNIX-based systems it is "/", for Mac OS 9 and earlier
it is ":". Other systems vary too. The best idea is to use a file
input and let the particular system work it out.

To allow for the systems noted above, your regular expression might be:

/[\\/:]$/
--
Rob

Sep 15 '06 #2

P: n/a
thanks. can you pls put that into a proper js statement. i am not sure
how to actually implement it.

Sep 15 '06 #3

P: n/a
cant get it to work. can someone help me pls.

Sep 15 '06 #4

P: n/a

pe******@gmail.com wrote:
cant get it to work. can someone help me pls.
Below is a small test. You'll note that using a file input requires
that an actual file is selected, users may have difficulty entering a
valid directory path.

Anyhow, if it's all too much, change the input type to 'text' and let
them copy/paste from Windows Explorer or a terminal window or whatever.

<title>Check path</title>

<script type="text/javascript">

function checkPath(form){
var path = form.divPath.value;
if (! /[\\/:]$/.test(path) ){
return confirm('The path you have entered is:\n' + path
+ '\nThis doesn\'t seem correct, it should end in'
+ ' "\\" or "/".'
+ '\nClick OK to send the path or Cancel to return'
+ ' to the form.');
}
}

</script>

<form action="" onsubmit="return checkPath(this);">
<p>Enter a directory path:<br>
<input type="file" name="divPath" size="100"><br>
<input type="submit" value="Submit path">
</p>
</form>
--
Rob

Sep 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.