Monday, March 12, 2012

getting only file name from fileupload control and checking for special character in file name :-JQuery

function ValidateThumbnail() {
//get file name
        var path = $("[id$=fileUploadControl]").val();
        var pos = path.lastIndexOf(path.charAt(path.indexOf(":") + 1));
      
        var f = path.substring(pos + 1);
       //check for special char
        if ((f.indexOf("#", 0) >= 0)
        || (f.indexOf("&", 0) >= 0)
        || (f.indexOf("*", 0) >= 0)
        || (f.indexOf(";", 0) >= 0)
        || (f.indexOf("$", 0) >= 0)
        || (f.indexOf("%", 0) >= 0)
        || (f.indexOf("^", 0) >= 0)
        || (f.indexOf("{", 0) >= 0)
        || (f.indexOf("}", 0) >= 0)
        || (f.indexOf("|", 0) >= 0)
        || (f.indexOf("/", 0) >= 0)
        || (f.indexOf("?", 0) >= 0)
        || (f.indexOf("~", 0) >= 0)
        || (f.indexOf(":", 0) >= 0)
        || (f.indexOf("<", 0) >= 0)
        || (f.indexOf(">", 0) >= 0)
        || (f.indexOf("\"", 0) >= 0)
        ) {
            alert("File: [" + f + "] contains invalid character");
            return false; //will stop button click event here
        }
        return true;
    }

No comments:

Post a Comment

SharePoint document metadata not updating

I faced a weird issue today, Metadata for document which has lookup column was not updating even after saving the item. There was no erro...