Filtering Textarea Input?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    Filtering Textarea Input?

    I want to filter textarea input to the following characters:

    A-Za-z0-9._

    How can I do this in JS and should this be done on a keyup or keydown
    press? When the user presses a char not in this list, I want nothing
    to happen in the textarea.

    Thanks...

  • Lee

    #2
    Re: Filtering Textarea Input?

    Ralph Freshour said:[color=blue]
    >
    >I want to filter textarea input to the following characters:
    >
    >A-Za-z0-9._
    >
    >How can I do this in JS and should this be done on a keyup or keydown
    >press? When the user presses a char not in this list, I want nothing
    >to happen in the textarea.[/color]

    You shouldn't do that at all. If the user presses a key and
    nothing happens, he's not going to say to himself "Oh, that
    must have been an illegal character, I'll try try another".
    He's going to say, "Dammit, this browser is acting up again!
    I had better close this page and restart and hope I can find
    my way back to this site".

    Audit the input onchange or onsubmit.

    Comment

    • |-|erc

      #3
      Re: Filtering Textarea Input?

      "Lee" <REM0VElbspamtr ap@cox.net> wrote[color=blue]
      > Ralph Freshour said:[color=green]
      > >
      > >I want to filter textarea input to the following characters:
      > >
      > >A-Za-z0-9._
      > >
      > >How can I do this in JS and should this be done on a keyup or keydown
      > >press? When the user presses a char not in this list, I want nothing
      > >to happen in the textarea.[/color]
      >
      > You shouldn't do that at all. If the user presses a key and
      > nothing happens, he's not going to say to himself "Oh, that
      > must have been an illegal character, I'll try try another".
      > He's going to say, "Dammit, this browser is acting up again!
      > I had better close this page and restart and hope I can find
      > my way back to this site".
      >
      > Audit the input onchange or onsubmit.
      >[/color]

      It's a valid technique imo, I just did some validate code today for a numeric field,
      most databases you type letters into a numeric field and thats when they restart.

      Herc



      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Filtering Textarea Input?

        "|-|erc" <usemyonlinefor m@wwwadamskingd om.com> writes:
        [color=blue]
        > It's a valid technique imo, I just did some validate code today for
        > a numeric field, most databases you type letters into a numeric
        > field and thats when they restart.[/color]

        Valid, yes. Problematic, yes too.

        Can you use tab to leave the input field? If not, that is a major
        usability no-no. Generally, cancelling the user's action without
        a warning is bad.

        Who cares what databases do? You should validate the input on the
        server, if there are any inputs that are problematic. You can validate
        on the client too to save the user a roundtrip to the server, but
        the easiest, and least intrusive, way is to do it in the onsubmit
        handler.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Lee

          #5
          Re: Filtering Textarea Input?

          |-|erc said:[color=blue]
          >
          >"Lee" <REM0VElbspamtr ap@cox.net> wrote[color=green]
          >> Ralph Freshour said:[color=darkred]
          >> >
          >> >I want to filter textarea input to the following characters:
          >> >
          >> >A-Za-z0-9._
          >> >
          >> >How can I do this in JS and should this be done on a keyup or keydown
          >> >press? When the user presses a char not in this list, I want nothing
          >> >to happen in the textarea.[/color]
          >>
          >> You shouldn't do that at all. If the user presses a key and
          >> nothing happens, he's not going to say to himself "Oh, that
          >> must have been an illegal character, I'll try try another".
          >> He's going to say, "Dammit, this browser is acting up again!
          >> I had better close this page and restart and hope I can find
          >> my way back to this site".
          >>
          >> Audit the input onchange or onsubmit.
          >>[/color]
          >
          >It's a valid technique imo, I just did some validate code today for a numeric
          >field,
          >most databases you type letters into a numeric field and thats when they
          >restart.[/color]

          Restricting a text field to digits is not as bad as restricting
          a textarea as the OP suggests, but it's still a bad idea.
          Audit the value afterwards and tell the user what's wrong.

          I assume you audit the data on the server side, too. Otherwise,
          I can send whatever garbage I like into your database.

          Comment

          Working...