2
I have a problem, I have a function that makes a debit in the database, but if the User changes the quantity by putting arithmetic operators the value is negative, thus crediting credits to the user instead of discounting.
how can I validate to not allow entering +/- and also validate the variable value in the same way.
my function that makes the debt
function debitashop(valor){
getCreditosPlayer(function(output) {
var creditosplayer = output;
creditosplayer = parseFloat(creditosplayer);
valor = valor.val(valor.replace(/[^\w]/gi, ''));
valor = parseFloat(valor);
valor = (creditosplayer - valor);
$.ajax({
url: "ajax/debita.php",
type: "POST",
data: "creditos="+valor,
success: function(dados){
getCreditosPlayer(function(output) {});
}
})
});
}
You want to validate whether the operator is in the middle of the input or just ignore it?
– Sorack
I want to be not allowed to enter operator, if type give replace pr ''
– Jefferson Mello Olynyki
Insert the following after line 3: creditosplayer = creditosplayer.replace(/[ w]/gi, '');
– Sorack
in the case of the variable value ? it is this that I need to validate
– Jefferson Mello Olynyki
would be that /[ 0-9. ]+/g, ""
– Jefferson Mello Olynyki
To accept only numbers yes
– Sorack
Post the answer and approve to someone who has a similar question posteiormently
– Sorack
done, thanks for the help ^^
– Jefferson Mello Olynyki
Possible duplicate of Extract only numbers from a Javascript text box
– Daniel Omine