/ Published in: JavaScript
This assumes a file field in a form with an id of "fileField", and the usage of the prototype library. Here you can use javascript as a first tier of security on restricting what kind of files may be uploaded with your form.
Expand |
Embed | Plain Text
function extractFileName (string) { if (string.indexOf('/') > -1) { fileName = string.substring(string.lastIndexOf('/') + 1, string.length); } else { fileName = string.substring(string.lastIndexOf('\\') + 1, string.length); } return fileName; } var fileField = $("fileField"); var fileName = extractFileName(fileField.value).replace(/^\s|\s$/g, ""); if (fileName.match(/([^\/\\]+)\.(gif|jpg|bmp|png|pjpeg)$/i) || fileName.blank() === true) { //good file } else { alert("I currently only accept the following file formats for the screenshot field: gif, jpg, bmp, png, pjpeg."); }
You need to login to post a comment.
