you are here: codestackercodes [RSS] → tag validate [RSS]

validate file extension

a very simple function.

extensions = new Array(".jpg", ".png");
function limitImage(file, extensions) {
	allowed = false;
	if (!file) return;

	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extensions.length; i++) {
		if (extensions[i] == ext) { allowed = true; break; }
	}
	return allowed;
}
Displaying 1 Code