Regular Expression....?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Regular Expression....?

    Hi

    I am looking for the regular expression for validating the allowed file types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the expression should not be case sensitive like it must match ZIP | zip | zIp.....

    regards
    rajeev
    Rajeev Soni Guest

  2. Similar Questions and Discussions

    1. Regular Expression
      Hi, I am writing a script that parses an html file (which has been retrieved as a scalar by LWP::UserAgent). The script looks for everything in...
    2. Regular expression help
      Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract...
    3. Regular expression for both first and last name?
      I'm new to regular expressions, can someone explain to me how I can write one that will check for 2 names, at least, for a name field? Thanks!...
    4. help on regular expression
      Hi, I need some help on regular expression... i have following in variable $total_count $total_count = "##I USBP 000001 10:38:09(000)...
    5. [PHP] REGULAR EXPRESSION HELP
      John wrote: Your "newline" may be \r\n or \r instead of just \n. -- ---John Holmes... Amazon Wishlist:...
  3. #2

    Default Re: Regular Expression....?

    Hi,

    Have a look at this adress : [url]http://www.regexlib.com/Default.aspx[/url]

    Regards,

    H. MAILLARD

    "Rajeev Soni" <rajeev_css@rediffmail.com> a écrit dans le message de news:
    [email]OfPzU2FUDHA.2092@TK2MSFTNGP10.phx.gbl[/email]...
    Hi

    I am looking for the regular expression for validating the allowed file
    types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the
    expression should not be case sensitive like it must match ZIP | zip |
    zIp.....

    regards
    rajeev


    Herve MAILLARD Guest

  4. #3

    Default Re: Regular Expression....?

    Hi,
    i have this validationexpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$"
    but in the above case i need to repilcate each extension twice once in lower case and once in upper case and this expression will not accept file extension as ".TxT".

    Is there any option in regular expression where we can specifiy to perform matching without considering the case of letter.

    thanks
    rajeev
    "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message news:et0A8AGUDHA.1552@TK2MSFTNGP10.phx.gbl...
    Hi
    I have already been to that, i have regular expression which validates given file type... but it is case sensitive and i need to create validation expression by getting the allowed file types from DB. So the there may be any number of extensions.

    Thanks
    Rajeev

    "Herve MAILLARD" <rvmaillard@free.fr> wrote in message news:3f1d4c12$0$1990$626a54ce@news.free.fr...
    > Hi,
    >
    > Have a look at this adress : [url]http://www.regexlib.com/Default.aspx[/url]
    >
    > Regards,
    >
    > H. MAILLARD
    >
    > "Rajeev Soni" <rajeev_css@rediffmail.com> a écrit dans le message de news:
    > [email]OfPzU2FUDHA.2092@TK2MSFTNGP10.phx.gbl[/email]...
    > Hi
    >
    > I am looking for the regular expression for validating the allowed file
    > types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the
    > expression should not be case sensitive like it must match ZIP | zip |
    > zIp.....
    >
    > regards
    > rajeev
    >
    >
    Rajeev Soni Guest

  5. #4

    Default Re: Regular Expression....?

    Yes: use the i modifier:
    /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$/i



    --
    Elliot M. Rodriguez, MCSD
    *** It would take 227 cans of Mountain Dew to kill me***



    "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message news:%238r74KGUDHA.2180@TK2MSFTNGP12.phx.gbl...
    Hi,
    i have this validationexpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$"
    but in the above case i need to repilcate each extension twice once in lower case and once in upper case and this expression will not accept file extension as ".TxT".

    Is there any option in regular expression where we can specifiy to perform matching without considering the case of letter.

    thanks
    rajeev
    "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message news:et0A8AGUDHA.1552@TK2MSFTNGP10.phx.gbl...
    Hi
    I have already been to that, i have regular expression which validates given file type... but it is case sensitive and i need to create validation expression by getting the allowed file types from DB. So the there may be any number of extensions.

    Thanks
    Rajeev

    "Herve MAILLARD" <rvmaillard@free.fr> wrote in message news:3f1d4c12$0$1990$626a54ce@news.free.fr...
    > Hi,
    >
    > Have a look at this adress : [url]http://www.regexlib.com/Default.aspx[/url]
    >
    > Regards,
    >
    > H. MAILLARD
    >
    > "Rajeev Soni" <rajeev_css@rediffmail.com> a écrit dans le message de news:
    > [email]OfPzU2FUDHA.2092@TK2MSFTNGP10.phx.gbl[/email]...
    > Hi
    >
    > I am looking for the regular expression for validating the allowed file
    > types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the
    > expression should not be case sensitive like it must match ZIP | zip |
    > zIp.....
    >
    > regards
    > rajeev
    >
    >
    Elliot M. Rodriguez Guest

  6. #5

    Default Re: Regular Expression....?

    Hi

    Thanks for the response... but placing "/" at start and end with "i" doesnot work..... it is also not accepting txt/TXT/doc/DOC extensions.
    I am using VS.NET 2003 with IE 6 sp1.

    regards
    rajeev
    "Elliot M. Rodriguez" <sbsp@bis.com> wrote in message news:uyNeEQGUDHA.940@TK2MSFTNGP11.phx.gbl...
    Yes: use the i modifier:
    /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$/i



    --
    Elliot M. Rodriguez, MCSD
    *** It would take 227 cans of Mountain Dew to kill me***



    "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message news:%238r74KGUDHA.2180@TK2MSFTNGP12.phx.gbl...
    Hi,
    i have this validationexpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$"
    but in the above case i need to repilcate each extension twice once in lower case and once in upper case and this expression will not accept file extension as ".TxT".

    Is there any option in regular expression where we can specifiy to perform matching without considering the case of letter.

    thanks
    rajeev
    "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message news:et0A8AGUDHA.1552@TK2MSFTNGP10.phx.gbl...
    Hi
    I have already been to that, i have regular expression which validates given file type... but it is case sensitive and i need to create validation expression by getting the allowed file types from DB. So the there may be any number of extensions.

    Thanks
    Rajeev

    "Herve MAILLARD" <rvmaillard@free.fr> wrote in message news:3f1d4c12$0$1990$626a54ce@news.free.fr...
    > Hi,
    >
    > Have a look at this adress : [url]http://www.regexlib.com/Default.aspx[/url]
    >
    > Regards,
    >
    > H. MAILLARD
    >
    > "Rajeev Soni" <rajeev_css@rediffmail.com> a écrit dans le message de news:
    > [email]OfPzU2FUDHA.2092@TK2MSFTNGP10.phx.gbl[/email]...
    > Hi
    >
    > I am looking for the regular expression for validating the allowed file
    > types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the
    > expression should not be case sensitive like it must match ZIP | zip |
    > zIp.....
    >
    > regards
    > rajeev
    >
    >
    Rajeev Soni Guest

  7. #6

    Default Re: Regular Expression....?

    "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in
    news:uEilzXGUDHA.1724@TK2MSFTNGP10.phx.gbl:
    > Hi
    >
    > Thanks for the response... but placing "/" at start and end with
    > "i" doesnot work..... it is also not accepting txt/TXT/doc/DOC
    > extensions. I am using VS.NET 2003 with IE 6 sp1.
    Rajeev,

    The /i modifier works in Perl, but not in .Net. To make a regex
    case-insensitive in .Net, use the case-insensitive (?i) mode
    modifier. It should be the first thing in the regex. For example:

    (?i)^.*?\.(txt|zip|doc|exe)$

    will match a string ending in .txt, .zip, .doc or .exe, regardless of
    the string's case.


    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.
    [url]http://www.crtimmonsinc.com/[/url]
    Chris R. Timmons Guest

  8. #7

    Default Re: Regular Expression....?

    Hi Chris,
    placing "(?i)" at the start of expression also doesnot work, it gives me JavaScript Error "Syntax Error in regular expression".
    i tried with both ways
    ValidationExpression = "(?i)^.*?\.(txt|zip|doc|exe)$"
    ValidationExpression = "(?i)^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+(?i)\.(txt|TXT|doc|DOC)$".

    I am using
    - WinXP Professional
    - VS.NET 2003
    - Framework 1.1
    - IE6 with SP1

    Thanks
    Rajeev

    "Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xns93C094F567DF0crtimmonscrtimmonsin@207.46.2 48.16...
    > "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in
    > news:uEilzXGUDHA.1724@TK2MSFTNGP10.phx.gbl:
    >
    > > Hi
    > >
    > > Thanks for the response... but placing "/" at start and end with
    > > "i" doesnot work..... it is also not accepting txt/TXT/doc/DOC
    > > extensions. I am using VS.NET 2003 with IE 6 sp1.
    >
    > Rajeev,
    >
    > The /i modifier works in Perl, but not in .Net. To make a regex
    > case-insensitive in .Net, use the case-insensitive (?i) mode
    > modifier. It should be the first thing in the regex. For example:
    >
    > (?i)^.*?\.(txt|zip|doc|exe)$
    >
    > will match a string ending in .txt, .zip, .doc or .exe, regardless of
    > the string's case.
    >
    >
    > Hope this helps.
    >
    > Chris.
    > -------------
    > C.R. Timmons Consulting, Inc.
    > [url]http://www.crtimmonsinc.com/[/url]
    Rajeev Soni Guest

  9. #8

    Default Re: Regular Expression....?

    "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in
    news:u4zGCMNUDHA.1556@TK2MSFTNGP10.phx.gbl:
    > Hi Chris,
    > placing "(?i)" at the start of expression also doesnot work, it
    > gives me JavaScript Error "Syntax Error in regular expression".
    > i tried with both ways
    > ValidationExpression = "(?i)^.*?\.(txt|zip|doc|exe)$"
    > ValidationExpression =
    > "(?i)^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w
    > ]*))+(?i)\.(txt|TXT|doc|DOC)$".
    >
    > I am using
    > - WinXP Professional
    > - VS.NET 2003
    > - Framework 1.1
    > - IE6 with SP1
    Rajeev,

    OK. I didn't know you were using JavaScript.

    For client-side JavaScript in IE6, there are two different syntaxes
    for regular expressions. They both work the same:

    [url]http://msdn.microsoft.com/library/en-[/url]
    us/script56/html/js56jsobjregexpression.asp

    Here's an example:


    <HTML>
    <HEAD>
    <TITLE>Case-Insensitive JavaScript Regular Expression</TITLE>
    </HEAD>
    <BODY>
    <SCRIPT language="JavaScript">
    <!--
    function IsFilenameValid_Version1(filename)
    {
    // Regex syntax using a RegExp object.
    var re = new RegExp("^.*?\\.(txt|zip|doc|exe)$", "i");
    return filename.match(re);
    }

    function IsFilenameValid_Version2(filename)
    {
    // Regex syntax using the native regex type.
    var re = /^.*?\\.(txt|zip|doc|exe)$/i;
    return filename.match(re);
    }

    var filename1 = "c:\\folder\\filename.TXT";
    var filename2 = "c:\\folder\\filename.ppt";

    if (IsFilenameValid_Version1(filename1))
    document.write(filename1 + " is valid.<BR>");
    else
    document.write(filename1 + " is not valid.<BR>");

    if (IsFilenameValid_Version2(filename2))
    document.write(filename2 + " is valid.<BR>");
    else
    document.write(filename2 + " is not valid.<BR>");

    //-->
    </SCRIPT>

    </BODY>
    </HTML>


    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.
    [url]http://www.crtimmonsinc.com/[/url]
    Chris R. Timmons Guest

  10. #9

    Default Re: Regular Expression....?

    Thanks Chris,
    i wrote Custom validator javascript function on to the client side using
    > function IsFilenameValid_Version1(filename)
    but
    > function IsFilenameValid_Version2(filename) doesnot seem to work try and give it a valid file... it returns false.
    thanks
    rajeev

    "Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xns93C15BB813F9Fcrtimmonscrtimmonsin@207.46.2 48.16...
    > "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in
    > news:u4zGCMNUDHA.1556@TK2MSFTNGP10.phx.gbl:
    >
    > > Hi Chris,
    > > placing "(?i)" at the start of expression also doesnot work, it
    > > gives me JavaScript Error "Syntax Error in regular expression".
    > > i tried with both ways
    > > ValidationExpression = "(?i)^.*?\.(txt|zip|doc|exe)$"
    > > ValidationExpression =
    > > "(?i)^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w
    > > ]*))+(?i)\.(txt|TXT|doc|DOC)$".
    > >
    > > I am using
    > > - WinXP Professional
    > > - VS.NET 2003
    > > - Framework 1.1
    > > - IE6 with SP1
    >
    > Rajeev,
    >
    > OK. I didn't know you were using JavaScript.
    >
    > For client-side JavaScript in IE6, there are two different syntaxes
    > for regular expressions. They both work the same:
    >
    > [url]http://msdn.microsoft.com/library/en-[/url]
    > us/script56/html/js56jsobjregexpression.asp
    >
    > Here's an example:
    >
    >
    > <HTML>
    > <HEAD>
    > <TITLE>Case-Insensitive JavaScript Regular Expression</TITLE>
    > </HEAD>
    > <BODY>
    > <SCRIPT language="JavaScript">
    > <!--
    > function IsFilenameValid_Version1(filename)
    > {
    > // Regex syntax using a RegExp object.
    > var re = new RegExp("^.*?\\.(txt|zip|doc|exe)$", "i");
    > return filename.match(re);
    > }
    >
    > function IsFilenameValid_Version2(filename)
    > {
    > // Regex syntax using the native regex type.
    > var re = /^.*?\\.(txt|zip|doc|exe)$/i;
    > return filename.match(re);
    > }
    >
    > var filename1 = "c:\\folder\\filename.TXT";
    > var filename2 = "c:\\folder\\filename.ppt";
    >
    > if (IsFilenameValid_Version1(filename1))
    > document.write(filename1 + " is valid.<BR>");
    > else
    > document.write(filename1 + " is not valid.<BR>");
    >
    > if (IsFilenameValid_Version2(filename2))
    > document.write(filename2 + " is valid.<BR>");
    > else
    > document.write(filename2 + " is not valid.<BR>");
    >
    > //-->
    > </SCRIPT>
    >
    > </BODY>
    > </HTML>
    >
    >
    > Hope this helps.
    >
    > Chris.
    > -------------
    > C.R. Timmons Consulting, Inc.
    > [url]http://www.crtimmonsinc.com/[/url]
    Rajeev Soni Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139