If to grab the extension a file remember names may have point before the extension which will make your script (/a/112999/3635) fail.
You can do it this way:
var v = "ARQUIVO.1.2.3.4.PNG";
var splt = v.split(".");
document.getElementById("nome").innerHTML = v;
document.getElementById("extensao").innerHTML = splt[splt.length - 1];
<div id="nome"></div>
<div id="extensao"></div>
If you want to remove the extension name you can use regex with .match
:
var v = "ARQUIVO.1.2.3.4.PNG";
var splt = v.match(/(.*?)\.([a-zA-Z0-9]+)$/);
document.getElementById("nomecompleto").innerHTML = splt[0];
document.getElementById("nome").innerHTML = splt[1];
document.getElementById("extensao").innerHTML = splt[2];
<div id="nomecompleto"></div>
<div id="nome"></div>
<div id="extensao"></div>
Using the back-end
But pay close attention, this type of checking is not safe, anyone can rename a file to an invalid extension. I don’t know which language to use, but it’s best to check mimetype, for example:
Using the Dropzone.js
How are you using the Dropzone.js
create a javascript for this is totally unnecessary, the Dropzone itself has the validation option, see the documentation http://www.dropzonejs.com/#config-acceptedFiles
Use this to accept only . jpg, . jpeg and . png (I don’t know if the check is secure or done by mimetype, but it creates the server-side check as previously said):
var myDropzone = new Dropzone("#meuid", {
url: "URL",
acceptedFiles: "image/jpeg,image/png"
});
JPG only:
var myDropzone = new Dropzone("#meuid", {
url: "URL",
acceptedFiles: "image/jpeg"
});
Or so for all types of images:
var myDropzone = new Dropzone("#meuid", {
url: "URL",
acceptedFiles: "image/*"
});
Very good answer, would help me in some other settings. because I’m having trouble defining the types as exemplified, in my div only is described as follows:
<div class="x_content">
 <form action="bb" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px; "></form>
 </div>
The rest is dynamic, based on this as I will define file types ?– Renan Rodrigues
@Renanrodrigues like this Javascript?
– Guilherme Nascimento
<script> var myDropzone = new Dropzone(".x_content", { url: "URL", acceptedFiles: "image/*" }); </script>
– Renan Rodrigues
@Renanrodrigues Tried to do so
var myDropzone = new Dropzone(".x_content", { url: "URL", acceptedFiles: "image/jpeg" });
??– Guilherme Nascimento
yes this very way
– Renan Rodrigues
@Renanrodrigues but not working? It is not filtering the files?
– Guilherme Nascimento