You don’t need scary plugins and you don’t need to use jQuery for something so trivial, you can do it by hand, learning the basics for real, of course.
An example of mask I made with pure JS helps understand how to do simply and even adapt later: /a/419538/3635, the process is basically timeout+regular expression+replace
Once this is done the question is the regex which you will need, in case there are four numbers after the point, so if you type up to 4 there is no point, I believe, so if you type 5 numbers it should be 9.9999, then the regex should look something like:
/^(\d+)(\d{4})$/
The first part of the regex ^(\d+)
takes the digits that must come before the point and the (\d{4})$
takes the last 4 digits. Note that it is necessary .replace(/\D+/, '');
to remove what are not digits.
The code went like this:
document.addEventListener('DOMContentLoaded', function () {
console.log('DOM carregou');
var campo1 = document.getElementById('campo1');
if (!campo1) return;
var campo1Timeout;
campo1.addEventListener('input', function () {
if (campo1Timeout) clearTimeout(campo1Timeout);
campo1Timeout = setTimeout(mascara, 200);
});
function mascara()
{
var value = campo1.value.replace(/\D+/, ''); //Remove tudo que não for numero
value = value.replace(/^(\d+)(\d{4})$/, '$1.$2');
campo1.value = value;
}
});
<input type="tel" name="campo1" id="campo1" placeholder="Seu numero">
There are plugins that facilitate this for you, one of them is jquery-Mask-money - https://github.com/plentz/jquery-maskmoney
– Pedro Henrique