4
I have n inputs, which are created dynamically. What happens is that they cannot accept zeros left on the following occasions:
0.24 -> The system accepts
00.24 -> The system automatically removes the zero on the left by 0.24
034.55 -> The system automatically removes the zero on the left by 34.55
That is, the zero on the left is only possible when there is leaning to the left of the point.
To make all inputs dynamically, I am starting with the following function:
$(document).ready(function () {
$('input').keypress(function(e) {
// Verificar os zero à esquerda
}
});
});
Is it possible here to check these conditions from scratch to the left? Or else using the onchage?
It is possible, just see if the information starts with zero and discard the key, but what is the actual problem you are trying to solve? What would be the problem of leaving the zero on the left and dealing with the application once the data is sent? This way you will have to treat situations like copy and paste, delete the point and two zeros "pull over" and a lot of conditions. It seems to me a XY problem.
– Bacco
@Bacco copy paste does not interest me, I just want to limit when the user is typing. The problem is that the client wants this validation in real time and I’m having trouble solving it..
– pc_oc
So if he glues a number with 000.23 and send, all right? Your client is in big XY trouble.
– Bacco
@Bacco yes, send... When you paste the number 000.23, he records only 0.23. But the problem is writing, is a client who has nothing to criticize, so criticize here.
– pc_oc
@Baccus may be the best option with the onchage in each input, no?
– pc_oc
It would have to cover the input, the change and still have browser that does not pass the events correctly. If it’s too important, the solution can be a timer looking at the value and adjusting it. As long as you start with two zeros, switch to one. But there is something else to solve: you have to subtract a position from the cursor at each change, otherwise the typing is kind of "weird".
– Bacco