file extension validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyanendar
    New Member
    • Jun 2007
    • 90

    #1

    file extension validation

    Hi ,
    I want to validate the file extension (.pdf) in through "RegularExpress ionValidator" (asp.net) .I am not able to decide what
    ValidationExpre ssion shall i use.
    Please help.
    Manohar
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    You need to check for the part after the " . " from right side of the filename.

    Comment

    • gyanendar
      New Member
      • Jun 2007
      • 90

      #3
      Originally posted by debasisdas
      You need to check for the part after the " . " from right side of the filename.
      Yes I need to check the extension of file.
      I am using validationExpre ssion="/^.+(\.(pdf))$"
      But its not working.
      Regards,
      Manohar

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by gyanendar
        Yes I need to check the extension of file.
        I am using validationExpre ssion="/^.+(\.(pdf))$"
        But its not working.
        Regards,
        Manohar
        If you have the file name in a string variable, you can use
        [CODE=cpp]if(fileName.End sWith(".pdf"))[/CODE]

        Comment

        • gyanendar
          New Member
          • Jun 2007
          • 90

          #5
          Originally posted by r035198x
          If you have the file name in a string variable, you can use
          [CODE=cpp]if(fileName.End sWith(".pdf"))[/CODE]
          I have file path stored in a variable.But this code works in code file.I need to do it from client side (java Script).
          I wrote a function and achive the result.
          But i want another solution.
          Regards,
          Manohar

          Comment

          • Sameerlucky
            New Member
            • Feb 2008
            • 6

            #6
            Gyanender,

            U can use the below example as reference...

            <asp:RegularExp ressionValidato r
            id="RegularExpr essionValidator 1" runat="server"
            ErrorMessage="O nly mp3, m3u or mpeg files are
            allowed!" ValidationExpre ssion="^(([a-zA-
            Z]:)|(\\{2}\w+)\$ ?)(\\(\w[\w
            ].*))+(.mp3|.MP3 |.mpeg|.MPEG|.m 3u|.M3U)$"
            ControlToValida te="File1">
            </asp:RegularExpr essionValidator >

            As ur case is to check for .pdf extension, then just repalce +(.mp3|.MP3|.mp eg|.MPEG|.m3u|. M3U) with +(.pdf|.PDF)

            Regards,
            Sameer

            Comment

            Working...