Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to validate file extension in javascript

//If your code above is simply trying to get the file extension of the filename then you can split the filename to an array by . and then use pop(). You can also put the valid extensions in an array and use indexOf() to check for validity. Try this:

var validExt = [ 'pdf', 'jpg', 'png' ];
var ext = this.value.split('.').pop();

if (validExt.indexOf(ext.toLowerCase()) == -1) {
    alert('Not allowed file type');
    this.value = '';
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: flutter wordspaceing 
Javascript :: how to do text to speech in javascript 
Javascript :: “javascript factorial” Code Answer’s' 
Javascript :: javascript date set weeks 
Javascript :: javascript replace vowel 
Javascript :: sh: generated/aesprim-browser.js: Permission denied 
Javascript :: js dom get website name 
Javascript :: jacksepticeye 
Javascript :: parse json express 
Javascript :: get position of element 
Javascript :: javascript print int with leading zeros 
Javascript :: react native margin 
Javascript :: how to add react scroll scrollable link 
Javascript :: ajax clear form 
Javascript :: how to display uploaded image in html using javascript 
Javascript :: require statement not part of import statement javascript 
Javascript :: index export in nodejs 
Javascript :: How to change favicon in nextjs. 
Javascript :: useeffect umnount 
Javascript :: nextjs tailwind 
Javascript :: react center a text 
Javascript :: how to change input required message react 
Javascript :: react nginx returns 404 after reload 
Javascript :: make the log do a jump in line js 
Javascript :: javascript create div with class 
Javascript :: fs in angular 
Javascript :: js wrap an element 
Javascript :: react native textinput lowercase 
Javascript :: add span after input jquery 
Javascript :: javascript hasownproperty 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =