Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Checking for a valid filename using Reg expressions - HELP!

Reply
Thread Tools

Checking for a valid filename using Reg expressions - HELP!

 
 
papillonimages@gmail.com
Guest
Posts: n/a
 
      02-24-2005
Please can someone help me, I am trying to write a Regular Expression
check for a valid (Windows) filename (cant believe I couldnt find one
on the net already?!?!?!). Anyway, here is what I have but it doesnt
fully work - e.g. it allows the use of quotes, and the ampersand in
some positions and I just cant correct it??! Sorry for being a dull
newbie.

TIA.

-------------------------------------------------

RegExp = /^["']?(.)?([^\|\&\<\>\;\*\?\\\\\/:]+\.\w+)["']?$/

 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      02-24-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Please can someone help me, I am trying to write a Regular Expression
> check for a valid (Windows) filename (cant believe I couldnt find one
> on the net already?!?!?!). Anyway, here is what I have but it doesnt
> fully work - e.g. it allows the use of quotes, and the ampersand in
> some positions and I just cant correct it??! Sorry for being a dull
> newbie.
>
> TIA.
>
> -------------------------------------------------
>
> RegExp = /^["']?(.)?([^\|\&\<\>\;\*\?\\\\\/:]+\.\w+)["']?$/
>


File name or file path?
Mick
 
Reply With Quote
 
 
 
 
papillonimages@gmail.com
Guest
Posts: n/a
 
      02-25-2005
file name - path not required...

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      02-25-2005
JRS: In article <(E-Mail Removed) .com>
, dated Thu, 24 Feb 2005 11:01:45, seen in news:comp.lang.javascript,
(E-Mail Removed) posted :
>Please can someone help me, I am trying to write a Regular Expression
>check for a valid (Windows) filename (cant believe I couldnt find one
>on the net already?!?!?!). Anyway, here is what I have but it doesnt
>fully work - e.g. it allows the use of quotes, and the ampersand in
>some positions and I just cant correct it??! Sorry for being a dull
>newbie.


>RegExp = /^["']?(.)?([^\|\&\<\>\;\*\?\\\\\/:]+\.\w+)["']?$/


For a start, the close quote must match the open quote. But only " can
be used for that.

RegExp = /^("?)(.)?([^\|\&\<\>\;\*\?\\\\\/:]+\.\w+)\1$/

I don't see why you allow a possible arbitrary character after the first
optional quote.

You appear to disallow the colon, meaning that you cannot specify a
drive, and you cannot specify a path. ISTM that in general the drive
and path should be allowed; include ([a-zA-Z]? and allow multiples
of what you have above with \ in between - which may be impossible.

You seem to require an extension; I'm not sure of that. In the
extension, you allow only word characters; an extension can, ISTM,
contain all the characters that the rest can - I frequently use $$$, for
example, and sometimes .

In your list of barred characters, I'd put colon before slash.
Javascript won't mind, but it will be a little easier to read.


If these are meant to be names of existing files, why bother? If the
file can be found, the name is OK; otherwise, it is wrong. If they are
meant to be names of new files, do you need to allow all possibilities?
you might list instead those that are needed, which has the benefit of
rejecting those of value above 126.


You should have given a written description of the intended criteria;
then it would have been easier to check your intent and your
implementation thereof.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Mick White
Guest
Posts: n/a
 
      02-25-2005
(E-Mail Removed) wrote:

> file name - path not required...
>

What are the rules for a Windows file name?
Mick
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking to see if an email address is valid... (non reg-ex) Peter L. Berghold Java 6 12-30-2006 12:10 AM
how to get 8.3 format filename from long filename jacobyv@sis.unibe.ch Java 1 06-15-2006 10:39 AM
Windows Reg Pro vs Tweak now Reg Cleaner vs Registry fix, vs RegCleaner jl Computer Support 3 05-31-2005 12:53 AM
Extract filename from a filename typed by user =?Utf-8?B?Sm9l?= ASP .Net 1 08-23-2004 11:29 PM
checking valid filename Alex Java 8 02-08-2004 02:01 AM



Advertisments