Consulting

Results 1 to 7 of 7

Thread: Solved: (Regular expression for) checking correct file name

  1. #1
    VBAX Regular
    Joined
    May 2005
    Location
    Tallinn
    Posts
    26
    Location

    Solved: (Regular expression for) checking correct file name

    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.

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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:
    Quote Originally Posted by Lammutaja
    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

  3. #3
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    do you mean to check for valid characters?
    I think there may something in the kb for that (!?)
    K :-)

  4. #4
    VBAX Regular
    Joined
    May 2005
    Location
    Tallinn
    Posts
    26
    Location
    I mean to check valid characters.
    J?ri.

  5. #5
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    J?ri,
    The following function should work exactly as you need:[vba]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 Function[/vba]Matt

  6. #6
    VBAX Regular
    Joined
    May 2005
    Location
    Tallinn
    Posts
    26
    Location
    Thank You very much!

  7. #7
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •