Revathi Vijay
Revathi Vijay

Reputation: 1308

How to restrict the files based on extension using Angular?

If I upload .exe or .twbx files then it show the alert message like you could not these type of files using angular 4 in typescript.

Upvotes: 2

Views: 6022

Answers (2)

Dileep Kumar Kottakota
Dileep Kumar Kottakota

Reputation: 127

You can use following code snippet to allow required formats

<input type="file" accept=".xls,.xlsx" />

Source: Limit file format when using <input type="file">?

Upvotes: 4

srikasi
srikasi

Reputation: 224

Please try this.It works for me.

var regexp;
var extension = fileName.substr(fileName.lastIndexOf('.'));
if ((extension.toLowerCase() == ".exe") ||
(extension.toLowerCase() == ".twbx"))
{
alert("Could not allow to upload .exe and .twbx files");
}

Upvotes: 3

Related Questions