I'm doing a data insertion site in the database and I do not want to be able to insert the euro symbol "€" in the input. Is there any way to block this?
I'm doing a data insertion site in the database and I do not want to be able to insert the euro symbol "€" in the input. Is there any way to block this?
Yes, you can initially do a check using Javascript, and for security another check on the imperative language in which you are creating your website, such as PHP, Ruby, Python, before writing to the database.
To check in Javascript, simply modify the type of submit button, from "submit" to "button" and add an event when clicking to execute a function in JavaScript in which it would verify the presence of the symbol "€" before sending .
In PHP before writing to the database it is highly advisable to check again.
Place this in your code, This code deletes the € symbol, for example:
1,43 € gets 1,43
But make sure that when you insert in DB you use the variable result.
<script>
function myFunction() {
var str = "a sua variavel aqui";
var patt1 = /[^€]/gi;
var result = str.match(patt1);
}
</script>
This resolves and still prevents typing letters
function allowOnlyNumbers(e) {
var tecla = (window.event) ? event.keyCode : e.which;
if ((tecla > 47 && tecla < 58)) return true;
else {
if (tecla == 8 || tecla == 0) return true;
else return false;
}};
i<input id="input" type="number" onkeypress="return allowOnlyNumbers(event)"/>