Regular Expression....?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajeev Soni

    #1

    Regular Expression....?

    Hi

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

    regards
    rajeev
  • Herve MAILLARD

    #2
    Re: Regular Expression....?

    Hi,

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

    Regards,

    H. MAILLARD

    "Rajeev Soni" <rajeev_css@red iffmail.com> a écrit dans le message de news:
    OfPzU2FUDHA.209 2@TK2MSFTNGP10. phx.gbl...
    Hi

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

    regards
    rajeev


    Comment

    • Rajeev Soni

      #3
      Re: Regular Expression....?

      Hi,
      i have this validationexpre ssion="^(([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@red iffmail.com> wrote in message news:et0A8AGUDH A.1552@TK2MSFTN GP10.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@fre e.fr> wrote in message news:3f1d4c12$0 $1990$626a54ce@ news.free.fr...[color=blue]
      > Hi,
      >
      > Have a look at this adress : http://www.regexlib.com/Default.aspx
      >
      > Regards,
      >
      > H. MAILLARD
      >
      > "Rajeev Soni" <rajeev_css@red iffmail.com> a écrit dans le message de news:
      > OfPzU2FUDHA.209 2@TK2MSFTNGP10. phx.gbl...
      > Hi
      >
      > I am looking for the regular expression for validating the allowed file
      > types to upload like files like "zip,pdf,doc,rt f,gif,jpg,png,t xt"; and the
      > expression should not be case sensitive like it must match ZIP | zip |
      > zIp.....
      >
      > regards
      > rajeev
      >
      >[/color]

      Comment

      • Elliot M. Rodriguez

        #4
        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@red iffmail.com> wrote in message news:%238r74KGU DHA.2180@TK2MSF TNGP12.phx.gbl. ..
        Hi,
        i have this validationexpre ssion="^(([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@red iffmail.com> wrote in message news:et0A8AGUDH A.1552@TK2MSFTN GP10.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@fre e.fr> wrote in message news:3f1d4c12$0 $1990$626a54ce@ news.free.fr...[color=blue]
        > Hi,
        >
        > Have a look at this adress : http://www.regexlib.com/Default.aspx
        >
        > Regards,
        >
        > H. MAILLARD
        >
        > "Rajeev Soni" <rajeev_css@red iffmail.com> a écrit dans le message de news:
        > OfPzU2FUDHA.209 2@TK2MSFTNGP10. phx.gbl...
        > Hi
        >
        > I am looking for the regular expression for validating the allowed file
        > types to upload like files like "zip,pdf,doc,rt f,gif,jpg,png,t xt"; and the
        > expression should not be case sensitive like it must match ZIP | zip |
        > zIp.....
        >
        > regards
        > rajeev
        >
        >[/color]

        Comment

        • Rajeev Soni

          #5
          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:uyNeEQGUDH A.940@TK2MSFTNG P11.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@red iffmail.com> wrote in message news:%238r74KGU DHA.2180@TK2MSF TNGP12.phx.gbl. ..
          Hi,
          i have this validationexpre ssion="^(([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@red iffmail.com> wrote in message news:et0A8AGUDH A.1552@TK2MSFTN GP10.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@fre e.fr> wrote in message news:3f1d4c12$0 $1990$626a54ce@ news.free.fr...[color=blue]
          > Hi,
          >
          > Have a look at this adress : http://www.regexlib.com/Default.aspx
          >
          > Regards,
          >
          > H. MAILLARD
          >
          > "Rajeev Soni" <rajeev_css@red iffmail.com> a écrit dans le message de news:
          > OfPzU2FUDHA.209 2@TK2MSFTNGP10. phx.gbl...
          > Hi
          >
          > I am looking for the regular expression for validating the allowed file
          > types to upload like files like "zip,pdf,doc,rt f,gif,jpg,png,t xt"; and the
          > expression should not be case sensitive like it must match ZIP | zip |
          > zIp.....
          >
          > regards
          > rajeev
          >
          >[/color]

          Comment

          • Chris R. Timmons

            #6
            Re: Regular Expression....?

            "Rajeev Soni" <rajeev_css@red iffmail.com> wrote in
            news:uEilzXGUDH A.1724@TK2MSFTN GP10.phx.gbl:
            [color=blue]
            > 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.[/color]

            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.

            Comment

            • Rajeev Soni

              #7
              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
              ValidationExpre ssion = "(?i)^.*?\.(txt |zip|doc|exe)$"
              ValidationExpre ssion = "(?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_NO SPAM_Xcrtimmons inc.com> wrote in message news:Xns93C094F 567DF0crtimmons crtimmonsin@207 .46.248.16...[color=blue]
              > "Rajeev Soni" <rajeev_css@red iffmail.com> wrote in
              > news:uEilzXGUDH A.1724@TK2MSFTN GP10.phx.gbl:
              > [color=green]
              > > 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.[/color]
              >
              > 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.
              > http://www.crtimmonsinc.com/[/color]

              Comment

              • Chris R. Timmons

                #8
                Re: Regular Expression....?

                "Rajeev Soni" <rajeev_css@red iffmail.com> wrote in
                news:u4zGCMNUDH A.1556@TK2MSFTN GP10.phx.gbl:
                [color=blue]
                > 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
                > ValidationExpre ssion = "(?i)^.*?\.(txt |zip|doc|exe)$"
                > ValidationExpre ssion =
                > "(?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[/color]

                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:

                http://msdn.microsoft.com/library/en-
                us/script56/html/js56jsobjregexp ression.asp

                Here's an example:


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

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

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

                if (IsFilenameVali d_Version1(file name1))
                document.write( filename1 + " is valid.<BR>");
                else
                document.write( filename1 + " is not valid.<BR>");

                if (IsFilenameVali d_Version2(file name2))
                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.

                Comment

                • Rajeev Soni

                  #9
                  Re: Regular Expression....?

                  Thanks Chris,
                  i wrote Custom validator javascript function on to the client side using [color=blue]
                  > function IsFilenameValid _Version1(filen ame)[/color]
                  but [color=blue]
                  > function IsFilenameValid _Version2(filen ame) doesnot seem to work try and give it a valid file... it returns false.[/color]

                  thanks
                  rajeev

                  "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in message news:Xns93C15BB 813F9Fcrtimmons crtimmonsin@207 .46.248.16...[color=blue]
                  > "Rajeev Soni" <rajeev_css@red iffmail.com> wrote in
                  > news:u4zGCMNUDH A.1556@TK2MSFTN GP10.phx.gbl:
                  > [color=green]
                  > > 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
                  > > ValidationExpre ssion = "(?i)^.*?\.(txt |zip|doc|exe)$"
                  > > ValidationExpre ssion =
                  > > "(?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[/color]
                  >
                  > 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:
                  >
                  > http://msdn.microsoft.com/library/en-
                  > us/script56/html/js56jsobjregexp ression.asp
                  >
                  > Here's an example:
                  >
                  >
                  > <HTML>
                  > <HEAD>
                  > <TITLE>Case-Insensitive JavaScript Regular Expression</TITLE>
                  > </HEAD>
                  > <BODY>
                  > <SCRIPT language="JavaS cript">
                  > <!--
                  > function IsFilenameValid _Version1(filen ame)
                  > {
                  > // Regex syntax using a RegExp object.
                  > var re = new RegExp("^.*?\\. (txt|zip|doc|ex e)$", "i");
                  > return filename.match( re);
                  > }
                  >
                  > function IsFilenameValid _Version2(filen ame)
                  > {
                  > // Regex syntax using the native regex type.
                  > var re = /^.*?\\.(txt|zip |doc|exe)$/i;
                  > return filename.match( re);
                  > }
                  >
                  > var filename1 = "c:\\folder\\fi lename.TXT";
                  > var filename2 = "c:\\folder\\fi lename.ppt";
                  >
                  > if (IsFilenameVali d_Version1(file name1))
                  > document.write( filename1 + " is valid.<BR>");
                  > else
                  > document.write( filename1 + " is not valid.<BR>");
                  >
                  > if (IsFilenameVali d_Version2(file name2))
                  > 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.
                  > http://www.crtimmonsinc.com/[/color]

                  Comment

                  Working...