Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
my textbox does not allowed to type + symbol,how to restrict it
Posted
Comments
Can you type + currently? Do you want to allow it?
ravikhoda 25-Feb-14 0:39am    
try onkeypress event of textbox and check for + sign ascii code .

1 solution

This will prevent input of '+' in the textbox:
XML
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
    var keyupHandler = function() {
        txtInput = this.value,
        lastChar = txtInput.charAt(txtInput.length-1)
        if (lastChar=='+'){
              this.value = txtInput.substr(0, txtInput.length-1);
        }
        return;
    };
    document.getElementById('textbox1').addEventListener('input', keyupHandler, false);
}
</script>
</head>
<body>
<input id="textbox1" />
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900