Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

vphope

macrumors newbie
Original poster
Jan 9, 2008
2
0
Hi

I am looking for a javascript regular expression to validate MAC file path

Example : path/to/filename.txt

Thanks
V
 

numero

macrumors regular
Jul 23, 2002
106
3
OR
This is the closest I found for a spec, but the page I need to see is gone.

http://developer.apple.com/technotes/tn/tn1150.html#CanonicalDecomposition

It would be nice to be able to find this page.
http://developer.apple.com/technotes/tn/tn1150table.html

The Unicode Decomposition table contains a list of characters that are illegal as part of an HFS Plus string, and the equivalent character(s) that must be used instead. Any character appearing in a column titled "Illegal", must be replaced by the character(s) in the column immediately to the right (titled "Replace With").​

If you come up with the list of illegal characters I can help you with the regex. The easy illegal character is ":", but this missing link promises some others.

-numero
 

vphope

macrumors newbie
Original poster
Jan 9, 2008
2
0
Hey, thanks for ur response.
I dont have any clue what might be the 'illegal' characters for MAC, i am using it for 1st time in my life :)

I found this regular Expression but giving error when i use with javascript (Invalid '(' )

^[/]*([^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}/)*[^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}$


var path = ifile.value;
var myRegExp = /^[/]*([^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}/)*[^/\\ \:\*\?"\<\>\|\.][^/\\\:\*\?\"\<\>\|]{0,63}$/;

if (myRegExp.test(path) == false )
{
alert(false);
} else
{
alert(true);
}

Any help is appreciated..
Thanks
V

This is the closest I found for a spec, but the page I need to see is gone.

http://developer.apple.com/technotes/tn/tn1150.html#CanonicalDecomposition

It would be nice to be able to find this page.
http://developer.apple.com/technotes/tn/tn1150table.html

The Unicode Decomposition table contains a list of characters that are illegal as part of an HFS Plus string, and the equivalent character(s) that must be used instead. Any character appearing in a column titled "Illegal", must be replaced by the character(s) in the column immediately to the right (titled "Replace With").​

If you come up with the list of illegal characters I can help you with the regex. The easy illegal character is ":", but this missing link promises some others.

-numero
 

numero

macrumors regular
Jul 23, 2002
106
3
OR
I haven't read through the expression very carefully, but the first thing I see is that:
^[/]*([
should probably be
^[/]*\([

I come to this conclusion because the closing ")" has a slash before it.

Some regex implementations use just ( and ) to surround expressions and some use \( and \). Looks like this system is using /( and /) (notice the direction change).

Let me know if this fixes it. If not then I'll dig a little deeper.

-numero
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
Don't really know javascript, but if the / is being used a string delimiter, then you will need to quote all of the /'s used within the regex pattern

Susan

Indeed, and here's what you need as a result,

Code:
var myRegExp = /^[\/]*([^\/\\ \:\*\?"\<\>\|\.][^\/\\\:\*\?\"\<\>\|]{0,63}\/)*[^\/\\ \:\*\?"\<\>\|\.][^\/\\\:\*\?\"\<\>\|]{0,63}$/;

The only from yours was as the above posters state all '/' were replaced with '\/' except for the first and last ones of course. I use BBedit and it's color-coded syntax was able to tell when the expression was correct (all of the text was blue), which was very helpful here. Just thought I'd mentioned that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.