SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    var re = /[jpg|jpeg]$/

    jpeg or jpg must be selected by the visitors.
    When I select ajaxtabscontent.zip, it displays "jpeg or jpg ". What can I do? Thanks...
    Code:
    <script type="text/javascript">
    function kontrol(){
    var el = document.getElementById('inputfile');
    var re = /[jpg|jpeg]$/
    if(re.test(el.value) ) { alert("jpeg or jpg "); }
    if(!re.test(el.value) ) { alert("not jpeg and jpg "); }
    }
    </script>
    </head>
    <body>
    <form action="giris.php">
    <input type="file"  id="inputfile" name="ad" onkeypress="return false;" onchange="kontrol()">
    </form>
    Last edited by muazzez; Jun 12, 2007 at 06:48.

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    /(jpg|jpeg)$/

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var re = /[jpg|jpeg]$/
    the brackets are a character range-matches ANY of the characters
    I don't know what the '|' does in this case- nothing good, apparently.

    you want re=/\.jp(e?)g$/
    to match a value ending with '.jpg' or '.jpeg'

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Third Stone From The Sun
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    /\.jp(?:e?)g$/
    but would be clearer as
    Code:
    /\.(?:jpg|jpeg|jfif)$/
    ?: - means don't store the result.
    My outdated site is down for a while now.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks...
    When I clicked the button, the window will display jpeg files or jpg files.
    It will not display htm files, gif files, zip files,...
    Is there any way do this? Thanks...

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,820
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The best you can do with JavaScript is to validatde that the file extension is the correct type after a file is selected.

    There is no way to restrict the list of files displayed in the browse window as that is part of your visitor's operating system and not part of your web page.

    There is no way with JavaScript to test that the file with a .jpg extension actually is a .jpg file and not something else renamed to try to fool your upload check. You need to examine the actual file content once it reaches the server to confirm that it is a real JPEG file and not something else in disguise.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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