View Full Version : Preventing unwanted characters

05-07-2006, 09:29 PM
Preventing unwanted characters

Instead of searching and replacing unwanted character in strings using cgi/perl, I would like to prevent some characters from ever being typed in text boxes and textfields. Two characters I would like to stop are "|" (pipe symbol) and the "carriage return". I am not even sure how to search and/or replace a carriage return in a string anyway. This may be a JavaScript function, because what I would really like to do is send an alert to tell the user that it is not allowed. Thanks for any ideas you may have on this.


Philip M
05-08-2006, 08:57 AM
if (/\r|\|/gi.test(theTextAreaOrBox.value)) { /// match carriage return or pipe (CR in text area only as textbox has only one line)
alert ("Invalid character");

05-08-2006, 05:58 PM
Thanks to everyone that read my post. I did the research and learnt a lot about validating. For now, I'm planning to use JavaScript to prevent most unwanted keystrocks from being entered. I am studing perl now so I will validate the input there to be sure and for users that turn off javascript.

Thanks, problem solved.