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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -