I have a text box in which I would like to do some validation. At the moment I have this code:
function updateChanger() {
var likeMessage = validateInput($("#like").val());
alert(likeMessage);
}
function validateInput(input) {
input = input.replace(/[^a-zA-Z0-9:\(\/\)\s\.,!~]/g, "");
return input;
}
This successfully eliminates the unwanted characters in the likeMessage variable, but the character is still entered in the text box. I would like to stop this.
I know this will be relevant $("#like").val(), but the only thing I can come up with is just chopping up the final character from the value of the text field. Would that be enough?
Thanks for any help!
source
share