Results 1 to 3 of 3

Thread: Regular Expression for directory path

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    55
    Answers
    2

    Default Regular Expression for directory path

    Hi

    Here i am writing the code for validating file path.

    var path="D:\\filepath\";
    var regex='^([\w]\\\\\|\\)([a-zA-Z0-9\-\_\\]+))$';
    if (!path.match(regex)){
    Ext.Msg.alert('Message','Please enter correct file structure.');
    return;
    }

    It was not working and i am getting the following error.

    "Uncaught SyntaxError: Invalid regular expression: + Unterminated character class"

    Kindly help me to resolve this issue.

    Thanks in advance

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Posts
    55
    Answers
    2

    Default

    I checked with
    "/^([\w]\: (\\\\|\\) ([a-zA-Z0-9\-\_\\]+))$/" regex also.

  3. #3
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505

    Default

    I'm not all that strong with regex, but here is an example for file types and a resource that is great for building and testing regex:

    Code:
    regex: /(.)+((\.csv)|(\.xls)(\w)?)$/i
    
    In this case it'll accept .csv or .xls (as well as any character after .xls such as .xlsx). Additinally it won't care whether the path is included or not - just looks for SOMETHING plus the approved file extension.
    http://gskinner.com/RegExr/

Posting Permissions

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