If it is to get the extension of a file remember names may have a dot before the extension what your script will do ( link ) fails.
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 name extension 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 backend
But pay close attention, this type of checking is not secure, anyone can rename a file to an invalid extension. I do not know which language to use, but it's best to check mimetype, for example:
Using Dropzone.js
As you are using Dropzone.js
create a javascript for this is totally unnecessary, the dropzone itself has the option of validation, see the documentation link
Use this to accept only .jpg, .jpeg and .png (I do not know if the check is safe or is done by mimetype, however it creates the server side check as above):
var myDropzone = new Dropzone("#meuid", {
url: "URL",
acceptedFiles: "image/jpeg,image/png"
});
Only JPG:
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/*"
});