JavaScript validates the function sharing of the image type of extension

  • 2020-03-30 02:47:57
  • OfStack


Foreground calls are as follows

OnClientClick="return fucCheckJpgAndGif(form1.File1.value);" -- Among them File1 Controls for uploading files 

Function code:


function fucCheckJpgAndGif(strFileName) {
    if (strFileName != "") {
        var strtype = strFileName.substring(strFileName.length - 4, strFileName.length);
        strtype = strtype.toLowerCase();
        if ((strtype == ".jpg") || (strtype == ".gif") || (strtype == "jpeg") || (strtype == ".bmp")) {
            return true;
        }
        else {
            alert(" Please upload jpg , gif or bmp Format of the picture, thank you! ");
            return false;
        }
    }
    alert(" Please upload jpg , gif or bmp Format of the picture, thank you! ");/* from http://yige.org/js/ */
    return false;

}


Related articles: