PDA

View Full Version : Solved: (Regular expression for) checking correct file name



Lammutaja
01-04-2006, 07:30 AM
Hi!
Can somebody give me regular expression (for Microsoft VBScript Regular Expressions 5.5) for checking correct name of file being saved in Windows XP Proffessional?

User will enter only first part of file:
For example user is saving new file with name "ThisIsmyfile.pdf".
User will enter only "ThisIsmyfile" and task is to check is this string correct for file name.

J?ri.

mvidas
01-04-2006, 07:45 AM
Hi J?ri,

I'd be glad to help you, but honestly I'm not sure what it is you're asking. What do you want to verify? What exactly do you mean by:

User will enter only "ThisIsmyfile" and task is to check is this string correct for file name.

How do you define correct/incorrect for a file name?
Matt

Killian
01-04-2006, 07:55 AM
do you mean to check for valid characters?
I think there may something in the kb for that (!?)

Lammutaja
01-04-2006, 08:01 AM
I mean to check valid characters.
J?ri.

mvidas
01-04-2006, 08:32 AM
J?ri,
The following function should work exactly as you need:Function ValidFileName(ByVal TheFileName As String) As Boolean
Dim RegEx As Object
Set RegEx = CreateObject("vbscript.regexp")
RegEx.Pattern = "[\\/:\*\?""<>\|]"
ValidFileName = Not RegEx.Test(TheFileName)
Set RegEx = Nothing
End FunctionMatt

Lammutaja
01-05-2006, 12:03 AM
Thank You very much!

mvidas
01-05-2006, 07:11 AM
Glad to help!

And to answer your question, you can make this thread 'Solved' by going to 'Thread Tools' near the top of the page, and choosing 'Mark Thread Solved'. Let us know if you have any more questions!

Matt