Reputation: 8836
How can I remove/disallow entering a dot .
on my textbox?
Upvotes: 3
Views: 6887
Reputation: 3620
Is this what you mean?
JavaScript:
function preventDot(id)
{
str = document.getElementById(id).value;
document.getElementById(id).value = (str.replace(".",""));
}
HTML:
<input type="text" id="input" onkeyup="preventDot(this.id)" />
Upvotes: 2
Reputation: 63522
Bind an event to your input
tag
<input type="text" onkeypress="return preventDot(event);" />
Then create a function like preventDot
that will return false
and prevent the key from being entered if the .
key is pressed
function preventDot(e)
{
var key = e.charCode ? e.charCode : e.keyCode;
if (key == 46)
{
return false;
}
}
Upvotes: 7