0

I searched in Google there has no option for validate file by using URL pattern.

I also have tried in my site. But pattern for file not working. Check my code -

<input type="file" class="form-control" id="mp3file_name" name="mp3file_name"  pattern="([^\s]+(\.(?i)(mp3))$)" accept="audio/mpeg, audio/mp3" required="required" />

Attribute accept working fine but I need to validate If I will uploading other files except mp3

Chinmay235
  • 3,456
  • 8
  • 49
  • 81

2 Answers2

2

Remove the pattern and just use:

<input type="file" class="form-control" id="mp3file_name" name="mp3file_name" accept="audio/mpeg, audio/mp3" required="required" />

Also as said by Mave:

The accept attribute is incredibly useful. It is a hint to browsers to only show files that are allowed for the current input. While it can typically be overridden by users, it helps narrow down the results for users by default, so they can get exactly what they're looking for without having to sift through a hundred different file types.

Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 154,660
  • 22
  • 177
  • 226
0

Please see File input 'accept' attribute - is it useful?:

The accept attribute is incredibly useful. It is a hint to browsers to only show files that are allowed for the current input. While it can typically be overridden by users, it helps narrow down the results for users by default, so they can get exactly what they're looking for without having to sift through a hundred different file types.

You can make it easier for users to browse through their files, but ultimately you have no control over it, as it is user input. Make sure you check the file in whatever language you receive the form in.

Community
  • 1
  • 1
Mave
  • 2,301
  • 3
  • 23
  • 51