Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preventing unwanted characters

    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.

    NevadaSam

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,149
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    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");
    }

  • #3
    New Coder
    Join Date
    May 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Samantha


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •