jquery - Regex to check filename extension before upload -
i'm trying validate file extension used regex have fails if there periods in filename or if there no extension @ all. appreciated. thanks!
current code:
// looks @ file type attemped , validates $('input[type="file"]').change(function () { var ext = this.value.match(/\.(.+)$/)[1]; switch (ext) { case 'bmp': case 'doc': case 'xls': $('#publicsubmit').attr('disabled', false); break; default: alert('this , invalid file extension. vaild extension(s): bmp, doc, xls'); //$('#publicsubmit').attr('disabled', true); this.value = ''; } });
if not depending on regex, use:
var ext = value.split('.').slice(-1)[0];
to files extension.
Comments
Post a Comment