Firefox: Filter Extended Ascii from Form

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

    Firefox: Filter Extended Ascii from Form

    My appologies if this ends up being a duplicate post. For some reason the
    first post never showed up.



    I've tried about 300 iterrations of this same ability, and none of them seem
    to work in Firefox. Take the following code for example. It WILL stop me
    from entering zero into the first text box, but it wont stop me from
    entering extended ascii characters (which is the final goal).

    Two items of note:
    1) Typing ALT+0156 inputs "o". And strangely enough the statusbar text gets
    set to "ALT0moz2 ALT0moz2 ALT0moz2". Only 3 ALT sequences show up when I
    actually type 4 characters
    2)Im working on a laptop that has no true numpad, so the '0' may be a result
    of me having to hold down a special function key in order to enable a numpad
    overlay.). So the check for altKey is correctly working, but attempting to
    cancel the ALT event fails.

    Does anyone know what is wrong with this, or have a working example that
    stops ALT keypresses / Extended chars in FIREFOX ?


    <script type="text/javascript">
    if(document.add EventListener){
    document.addEve ntListener("key press", HandleEnterKey, true);
    }
    else{
    document.attach Event("onkeypre ss", HandleEnterKey) ;
    }


    // Handle the enter key for a section of a form, binding it to the provided
    submit buton
    function HandleEnterKey( event) {
    var nav = window.Event ? true : false;
    if (nav) {
    return NetscapeEventHa ndler_KeyDown(e vent);
    } else {
    return MicrosoftEventH andler_KeyDown( );
    }
    }

    function NetscapeEventHa ndler_KeyDown(e ) {
    if (e.which == 48) {
    window.status = window.status + e.which + "moz1 ";
    e.returnValue = false;
    e.cancel = true;
    e.preventDefaul t();
    return false;
    } else if (e.altKey) {
    window.status = window.status + "ALT" + e.which + "moz2 ";
    e.returnValue = false;
    e.cancel = true;
    e.stopPropagati on();
    e.preventDefaul t();
    return false;
    }
    return true;
    }
    </script>
    </head>
    <body>
    <form action="" id="theForm">
    <input type="text" id="i1" name="i1" />
    </form>


  • RobG

    #2
    Re: Firefox: Filter Extended Ascii from Form

    bgbauer70 wrote:
    [...][color=blue]
    >
    > // Handle the enter key for a section of a form, binding it to the provided
    > submit buton
    > function HandleEnterKey( event) {
    > var nav = window.Event ? true : false;
    > if (nav) {
    > return NetscapeEventHa ndler_KeyDown(e vent);
    > } else {
    > return MicrosoftEventH andler_KeyDown( );
    > }
    > }[/color]

    I don't have a solution, but the following is possibly a better way to
    determine appropriate the event model:

    function HandleEnterKey( e ) {
    if ( e ) {
    return NetscapeEventHa ndler_KeyDown( e );
    } else if ( window.event ) {
    return MicrosoftEventH andler_KeyDown( );
    }
    }

    If you are trying to restrict the characters that can be entered into a
    text input, you are probably better off to use a regular expression to
    test its value rather than trying to intercept keystrokes.

    For example, I can enter a zero into the text input by copying and
    pasting - ctrl+v or Edit->Paste - without using the zero key.

    [...]

    --
    Rob

    Comment

    • bgbauer70

      #3
      Re: Firefox: Filter Extended Ascii from Form

      Hi Rob,

      Is there a way to regex test based on ascii #? The problem is I just want
      to filter out high ascii ( >127 ).


      "RobG" <rgqld@iinet.ne t.au> wrote in message
      news:432d4bc6$0 $11760$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
      > bgbauer70 wrote:
      > [...][color=green]
      >>
      >> // Handle the enter key for a section of a form, binding it to the
      >> provided
      >> submit buton
      >> function HandleEnterKey( event) {
      >> var nav = window.Event ? true : false;
      >> if (nav) {
      >> return NetscapeEventHa ndler_KeyDown(e vent);
      >> } else {
      >> return MicrosoftEventH andler_KeyDown( );
      >> }
      >> }[/color]
      >
      > I don't have a solution, but the following is possibly a better way to
      > determine appropriate the event model:
      >
      > function HandleEnterKey( e ) {
      > if ( e ) {
      > return NetscapeEventHa ndler_KeyDown( e );
      > } else if ( window.event ) {
      > return MicrosoftEventH andler_KeyDown( );
      > }
      > }
      >
      > If you are trying to restrict the characters that can be entered into a
      > text input, you are probably better off to use a regular expression to
      > test its value rather than trying to intercept keystrokes.
      >
      > For example, I can enter a zero into the text input by copying and
      > pasting - ctrl+v or Edit->Paste - without using the zero key.
      >
      > [...]
      >
      > --
      > Rob[/color]


      Comment

      • Mick White

        #4
        Re: Firefox: Filter Extended Ascii from Form

        bgbauer70 wrote:
        [color=blue]
        > Is there a way to regex test based on ascii #? The problem is I just want
        > to filter out high ascii ( >127 ).
        >[/color]

        A string method:
        String.charCode At(index)


        Returns the decimal Unicode value, but for most characters it's the same
        as AASCI.
        Mick

        Comment

        • RobG

          #5
          Re: Firefox: Filter Extended Ascii from Form

          bgbauer70 wrote:[color=blue]
          > Hi Rob,
          >
          > Is there a way to regex test based on ascii #? The problem is I just want
          > to filter out high ascii ( >127 ).
          >[/color]

          There is no such thing as "high ascii" - it stops at 127, there are no
          ASCII characters beyond it. As Mick suggests, you could use the Unicode
          value to discriminate or you could make a regular expression that tests
          for the 95 displayable ASCII characters. I think the former is simpler.

          There is a relevant thread here in c.i.a.html:

          <URL:http://groups.google.c o.uk/group/comp.infosystem s.www.authoring .html/browse_frm/thread/aa2508a3174597d 5/9d5f6ded0144e4c 8?q=high-ascii+character &rnum=1&hl=en#9 d5f6ded0144e4c8 >

          An an excellent piece on HTML character encoding here:

          <URL:http://ppewww.ph.gla.a c.uk/~flavell/charset/checklist>


          [...]


          --
          Rob

          Comment

          • bgbauer70

            #6
            Re: Firefox: Filter Extended Ascii from Form


            "RobG" <rgqld@iinet.ne t.au> wrote in message
            news:1mmXe.508$ uQ6.25883@news. optus.net.au...[color=blue]
            > bgbauer70 wrote:[color=green]
            >> Hi Rob,
            >>
            >> Is there a way to regex test based on ascii #? The problem is I just
            >> want to filter out high ascii ( >127 ).
            >>[/color]
            >
            > There is no such thing as "high ascii" - it stops at 127, there are no
            > ASCII characters beyond it.[/color]

            This is just not true. The extended ASCII character set has 255.


            Comment

            • ASM

              #7
              Re: Firefox: Filter Extended Ascii from Form

              bgbauer70 wrote:[color=blue]
              > "RobG" <rgqld@iinet.ne t.au> wrote in message
              > news:1mmXe.508$ uQ6.25883@news. optus.net.au...
              >[color=green]
              >>bgbauer70 wrote:
              >>[color=darkred]
              >>>Hi Rob,
              >>>
              >>>Is there a way to regex test based on ascii #? The problem is I just
              >>>want to filter out high ascii ( >127 ).[/color]
              >>
              >>There is no such thing as "high ascii" - it stops at 127, there are no
              >>ASCII characters beyond it.[/color]
              >
              >
              > This is just not true. The extended ASCII character set has 255.[/color]

              here(*) :

              I see ASCII with 126 carateres
              and (extended ASCII ?) charset : CP437
              with 255 caracteres

              (*) use alternative css 'Tableaux en pixels'
              --
              Stephane Moriaux et son [moins] vieux Mac

              Comment

              • Baconbutty

                #8
                Re: Firefox: Filter Extended Ascii from Form

                To filter out, you could perhaps filter out from >126 as 127 is unused.

                The reg exp woud be:-

                var r=/[\x7F-\xFF]*/g;
                s=s.replace(r," ");

                Comment

                • Mick White

                  #9
                  Re: Firefox: Filter Extended Ascii from Form

                  Baconbutty wrote:[color=blue]
                  > To filter out, you could perhaps filter out from >126 as 127 is unused.
                  >
                  > The reg exp woud be:-
                  >
                  > var r=/[\x7F-\xFF]*/g;
                  > s=s.replace(r," ");
                  >[/color]
                  Good, but this replaces control characters too (\x0 - \x1f )
                  Mick

                  Comment

                  • RobG

                    #10
                    Re: Firefox: Filter Extended Ascii from Form

                    bgbauer70 wrote:[color=blue]
                    > "RobG" <rgqld@iinet.ne t.au> wrote in message
                    > news:1mmXe.508$ uQ6.25883@news. optus.net.au...
                    >[color=green]
                    >>bgbauer70 wrote:
                    >>[color=darkred]
                    >>>Hi Rob,
                    >>>
                    >>>Is there a way to regex test based on ascii #? The problem is I just
                    >>>want to filter out high ascii ( >127 ).
                    >>>[/color]
                    >>
                    >>There is no such thing as "high ascii" - it stops at 127, there are no
                    >>ASCII characters beyond it.[/color]
                    >
                    >
                    > This is just not true. The extended ASCII character set has 255.[/color]

                    There are a vast array of extended ASCII sets, IBM alone developed over
                    three hundred of them[1], but none of them are standards. The following
                    reference seems a pretty good history:

                    <URL: http://en.wikipedia.org/wiki/ASCII >

                    ASCII consists of 128 characters mapped to a decimal range of 0 to 127
                    inclusive. Because it's been around for over 40 years, it's been
                    bastardised many times but:

                    "...most widely-used form uses the ANSI X3.4-1986 definition, also
                    standardized as ECMA-6, ISO/IEC 646:1991 International Reference
                    Version, ITU-T Recommendation T.50 (09/92), and Request for Comments
                    RFC 20."

                    In other words, the ASCII 7 bit character set has been standardised by a
                    number of official international standards-setting organisations[2].

                    I'm happy to be proven wrong, but you'll need to find a reference to an
                    official standard for 'the extended ASCII character set' to do it.


                    1.
                    <URL:
                    http://www-03.ibm.com/servers/eserve...codepages.html[color=blue]
                    >[/color]

                    2.
                    Standard ECMA-6:
                    <URL:
                    http://www.ecma-international.org/pu...T/Ecma-006.pdf >





                    --
                    Rob

                    Comment

                    • bgbauer70

                      #11
                      Re: Firefox: Filter Extended Ascii from Form

                      Thanks! Thats exactly what I was wondering if you could do.


                      "Mick White" <mwhite13BOGUS@ rochester.rr.co m> wrote in message
                      news:59yXe.8144 1$EX.12353@twis ter.nyroc.rr.co m...[color=blue]
                      > Baconbutty wrote:[color=green]
                      >> To filter out, you could perhaps filter out from >126 as 127 is unused.
                      >>
                      >> The reg exp woud be:-
                      >>
                      >> var r=/[\x7F-\xFF]*/g;
                      >> s=s.replace(r," ");
                      >>[/color]
                      > Good, but this replaces control characters too (\x0 - \x1f )
                      > Mick[/color]


                      Comment

                      • Mick White

                        #12
                        Re: Firefox: Filter Extended Ascii from Form

                        Mick White wrote:
                        [color=blue]
                        > Baconbutty wrote:
                        >[color=green]
                        >> To filter out, you could perhaps filter out from >126 as 127 is unused.
                        >>
                        >> The reg exp woud be:-
                        >>
                        >> var r=/[\x7F-\xFF]*/g;
                        >> s=s.replace(r," ");
                        >>[/color]
                        > Good, but this replaces control characters too (\x0 - \x1f )
                        > Mick[/color]

                        Oops, ignore me.
                        Mick

                        Comment

                        • bgbauer70

                          #13
                          Re: Firefox: Filter Extended Ascii from Form

                          Just thought I'd post an update. I got keypress filtering working finally.

                          For onblur handling (to cover paste ops) I ended up using the following.

                          if(/[\u0080-\uFFFF]+/i.test(targ.val ue)) {
                          window.status = "FAILED!"
                          } else {
                          window.status = "PASSED!"
                          }

                          This way higher unicode chars were included. I also opted against replace,
                          because if for example a person has 1 non-us english character in their
                          address, and I strip that character out, they may not visually see that its
                          missing, and it could lead to errors in the data. I am instead going to
                          alert() them to the error, and focus/select or highlight the offending
                          field.

                          Thanks for the help guys! I didnt realise you could regex based on char
                          code. Just what I needed in this situation. Very helpful!




                          "Mick White" <mwhite13BOGUS@ rochester.rr.co m> wrote in message
                          news:59yXe.8144 1$EX.12353@twis ter.nyroc.rr.co m...[color=blue]
                          > Baconbutty wrote:[color=green]
                          >> To filter out, you could perhaps filter out from >126 as 127 is unused.
                          >>
                          >> The reg exp woud be:-
                          >>
                          >> var r=/[\x7F-\xFF]*/g;
                          >> s=s.replace(r," ");
                          >>[/color]
                          > Good, but this replaces control characters too (\x0 - \x1f )
                          > Mick[/color]


                          Comment

                          • bgbauer70

                            #14
                            Re: Firefox: Filter Extended Ascii from Form

                            Strike that... I had to switch back to using the hex regex. The unicode
                            char set isnt layed out how I thought.


                            "bgbauer70" <user@sbcglobal .net> wrote in message
                            news:zvoYe.5651 $6e1.4430@newss vr14.news.prodi gy.com...[color=blue]
                            > Just thought I'd post an update. I got keypress filtering working
                            > finally.
                            >
                            > For onblur handling (to cover paste ops) I ended up using the following.
                            >
                            > if(/[\u0080-\uFFFF]+/i.test(targ.val ue)) {
                            > window.status = "FAILED!"
                            > } else {
                            > window.status = "PASSED!"
                            > }
                            >
                            > This way higher unicode chars were included. I also opted against
                            > replace, because if for example a person has 1 non-us english character in
                            > their address, and I strip that character out, they may not visually see
                            > that its missing, and it could lead to errors in the data. I am instead
                            > going to alert() them to the error, and focus/select or highlight the
                            > offending field.
                            >
                            > Thanks for the help guys! I didnt realise you could regex based on char
                            > code. Just what I needed in this situation. Very helpful!
                            >
                            >
                            >
                            >
                            > "Mick White" <mwhite13BOGUS@ rochester.rr.co m> wrote in message
                            > news:59yXe.8144 1$EX.12353@twis ter.nyroc.rr.co m...[color=green]
                            >> Baconbutty wrote:[color=darkred]
                            >>> To filter out, you could perhaps filter out from >126 as 127 is unused.
                            >>>
                            >>> The reg exp woud be:-
                            >>>
                            >>> var r=/[\x7F-\xFF]*/g;
                            >>> s=s.replace(r," ");
                            >>>[/color]
                            >> Good, but this replaces control characters too (\x0 - \x1f )
                            >> Mick[/color]
                            >
                            >[/color]


                            Comment

                            Working...