上传文件格式只能是.gif或.jpg,做一个客户端验证空间,需要这样的一个正则表达式

解决方案 »

  1.   

    ^[0-9A-Za-z_ ]+(.[jJ][pP][gG]|.[gG][iI][fF])$
      

  2.   

    Expression:  ^[0-9A-Za-z_ ]+(.[jJ][pP][gG]|.[gG][iI][fF])$
        
    Description:  Matches HTML image leaf filenames.  
    Matches:  [good.gif], [go d.GIf], [goo_d.jPg]  [ More Details]  
    Non-Matches:  [junk], [bad.bad.gif], [slash\gif.]  
      

  3.   

    给个Javascript你吧
    var fileName=document.getElementById("myFile").value;
    if(fileName=="")
    return;
    var exName=fileName.substr(fileName.lastIndexOf(".")+1).toUpperCase()
    //alert(exName)
    if(exName=="JPG"||exName=="BMP"||exName=="GIF")
    {
    document.getElementById("myimg").src=fileName
    }
    else
    {
    alert("请选择正确的图片文件")
    document.getElementById("myFile").value=""
    }
      

  4.   

    ^[^.]*.jpg|[^.]*.gif$或者就获得文件的后缀名fileextname
    然后和jpg gif比较filepath = Me.fileup.PostedFile.FileName
    fileextname = filepath.Substring(filepath.LastIndexOf(".") + 1)