"Intercepting" user input into text box and removing it
Posted
by James P
on Stack Overflow
See other posts from Stack Overflow
or by James P
Published on 2010-06-08T01:01:45Z
Indexed on
2010/06/08
1:12 UTC
Read the original article
Hit count: 240
I have a text box that I would like to do some validation on. At the moment I have this code:
function updateChanger() {
// Validate input
var likeMessage = validateInput($("#like").val());
alert(likeMessage);
}
function validateInput(input) {
input = input.replace(/[^a-zA-Z0-9:\(\/\)\s\.,!~]/g, "");
return input;
}
This successfully trims out unwanted characters in the likeMessage variable, but the character still gets entered into the text box. I would like to stop that from happening.
I know it will have something to do with $("#like").val()
but the only thing I can think of is just chopping off the end character from the text box value, would this suffice?
Thanks for any help!
© Stack Overflow or respective owner