By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Firefox: Filter Extended Ascii from Form

P: n/a
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.addEventListener){
document.addEventListener("keypress", HandleEnterKey, true);
}
else{
document.attachEvent("onkeypress", 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 NetscapeEventHandler_KeyDown(event);
} else {
return MicrosoftEventHandler_KeyDown();
}
}

function NetscapeEventHandler_KeyDown(e) {
if (e.which == 48) {
window.status = window.status + e.which + "moz1 ";
e.returnValue = false;
e.cancel = true;
e.preventDefault();
return false;
} else if (e.altKey) {
window.status = window.status + "ALT" + e.which + "moz2 ";
e.returnValue = false;
e.cancel = true;
e.stopPropagation();
e.preventDefault();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="" id="theForm">
<input type="text" id="i1" name="i1" />
</form>
Sep 17 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
bgbauer70 wrote:
[...]

// 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 NetscapeEventHandler_KeyDown(event);
} else {
return MicrosoftEventHandler_KeyDown();
}
}


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 NetscapeEventHandler_KeyDown( e );
} else if ( window.event ) {
return MicrosoftEventHandler_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
Sep 18 '05 #2

P: n/a
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" <rg***@iinet.net.au> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...
bgbauer70 wrote:
[...]

// 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 NetscapeEventHandler_KeyDown(event);
} else {
return MicrosoftEventHandler_KeyDown();
}
}


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 NetscapeEventHandler_KeyDown( e );
} else if ( window.event ) {
return MicrosoftEventHandler_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

Sep 18 '05 #3

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


A string method:
String.charCodeAt(index)
Returns the decimal Unicode value, but for most characters it's the same
as AASCI.
Mick
Sep 18 '05 #4

P: n/a
bgbauer70 wrote:
Hi Rob,

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


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.co.uk/group/comp.infosystems.www.authoring.html/browse_frm/thread/aa2508a3174597d5/9d5f6ded0144e4c8?q=high-ascii+character&rnum=1&hl=en#9d5f6ded0144e4c8>

An an excellent piece on HTML character encoding here:

<URL:http://ppewww.ph.gla.ac.uk/~flavell/charset/checklist>
[...]
--
Rob
Sep 18 '05 #5

P: n/a

"RobG" <rg***@iinet.net.au> wrote in message
news:1m*****************@news.optus.net.au...
bgbauer70 wrote:
Hi Rob,

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


There is no such thing as "high ascii" - it stops at 127, there are no
ASCII characters beyond it.


This is just not true. The extended ASCII character set has 255.
Sep 19 '05 #6

P: n/a
ASM
bgbauer70 wrote:
"RobG" <rg***@iinet.net.au> wrote in message
news:1m*****************@news.optus.net.au...
bgbauer70 wrote:
Hi Rob,

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


There is no such thing as "high ascii" - it stops at 127, there are no
ASCII characters beyond it.

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


here(*) :
http://www.miakinen.net/vrac/c08/charsets
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
Sep 19 '05 #7

P: n/a
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,"");

Sep 19 '05 #8

P: n/a
Baconbutty wrote:
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,"");

Good, but this replaces control characters too (\x0 - \x1f )
Mick
Sep 19 '05 #9

P: n/a
bgbauer70 wrote:
"RobG" <rg***@iinet.net.au> wrote in message
news:1m*****************@news.optus.net.au...
bgbauer70 wrote:
Hi Rob,

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

There is no such thing as "high ascii" - it stops at 127, there are no
ASCII characters beyond it.

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


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


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

--
Rob
Sep 19 '05 #10

P: n/a
Thanks! Thats exactly what I was wondering if you could do.
"Mick White" <mw***********@rochester.rr.com> wrote in message
news:59******************@twister.nyroc.rr.com...
Baconbutty wrote:
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,"");

Good, but this replaces control characters too (\x0 - \x1f )
Mick

Sep 19 '05 #11

P: n/a
Mick White wrote:
Baconbutty wrote:
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,"");

Good, but this replaces control characters too (\x0 - \x1f )
Mick


Oops, ignore me.
Mick
Sep 19 '05 #12

P: n/a
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.value)) {
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" <mw***********@rochester.rr.com> wrote in message
news:59******************@twister.nyroc.rr.com...
Baconbutty wrote:
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,"");

Good, but this replaces control characters too (\x0 - \x1f )
Mick

Sep 22 '05 #13

P: n/a
Strike that... I had to switch back to using the hex regex. The unicode
char set isnt layed out how I thought.
"bgbauer70" <us**@sbcglobal.net> wrote in message
news:zv*****************@newssvr14.news.prodigy.co m...
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.value)) {
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" <mw***********@rochester.rr.com> wrote in message
news:59******************@twister.nyroc.rr.com...
Baconbutty wrote:
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,"");

Good, but this replaces control characters too (\x0 - \x1f )
Mick


Sep 22 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.