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 = '';
}
Also in JavaScript:
- hide automatically show and hide javascript
- linux command to install standard js
- two dimensional array in javascript example code
- ajax calls
- javascript extract number from string
- react $ r component instance console
- self invoking function javascript es6
- getelementbyid javascript
- electron send message from renderer to main
- dotenv not loading process.env in node
- foreach await js
- javascript get unique values from array
- js set visibility on timeout
- generate 50 random numbers between 1 and 500 in javascript
- angular how to copy text with button
- password strength checker javascript
- close browser tab javascript
- ajax vs rest
- "rbac" react redux navigation bar
- javascript substring last character
- javascript remove line breaks from string
- npm express
- js convert order to char
- laravel json eloquent