Created
March 9, 2012 01:13
-
-
Save stephensprinkle-zz/2004455 to your computer and use it in GitHub Desktop.
Jquery File Extension Validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validVideoFileExtensions = [ ".mp4", ".m4v", ".mov" ] | |
validAudioFileExtensions = [ ".mp3", ".m4a" ] | |
$("input#sermon_video").live "change", -> | |
if this.type is "file" | |
sFileName = this.value | |
if sFileName.length > 0 | |
blnValid = false | |
j = 0 | |
while j < validVideoFileExtensions.length | |
sCurExtension = validVideoFileExtensions[j] | |
if sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() is sCurExtension.toLowerCase() | |
blnValid = true | |
$("input[type=submit]").removeAttr("disabled"); | |
break | |
j++ | |
unless blnValid | |
$("input[type=submit]").attr("disabled", "disabled"); | |
alert "Sorry, " + sFileName + " is invalid, allowed extensions are: " + validVideoFileExtensions.join(", ") | |
return false | |
$("input#sermon_audio").live "change", -> | |
if this.type is "file" | |
sFileName = this.value | |
if sFileName.length > 0 | |
blnValid = false | |
j = 0 | |
while j < validAudioFileExtensions.length | |
sCurExtension = validAudioFileExtensions[j] | |
if sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() is sCurExtension.toLowerCase() | |
blnValid = true | |
$("input[type=submit]").removeAttr("disabled"); | |
break | |
j++ | |
unless blnValid | |
$("input[type=submit]").attr("disabled", "disabled"); | |
alert "Sorry, " + sFileName + " is invalid, allowed extensions are: " + validAudioFileExtensions.join(", ") | |
return false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment