473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.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
13 7739
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
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
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
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

"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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII...
3
by: JSM | last post by:
Hi, I am just trying to port an existing simple encryption routine to C#. this routine simply adds/substracts 10 ascii characters to each character in a text file (except quotes). The routine...
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
4
by: =?Utf-8?B?Um9zaGFuIFIuRA==?= | last post by:
Hi All, I am new to C# programming; I am developing an application for recording audio data using voice modem. I am using HyperTerminal to manually process audio data. The modem when configured...
13
by: ramif | last post by:
Is there a way to print extended ASCII in C?? I tried to code something, but it only displays strange symbols. here is my code: main() { char chr = 177; //stores the extended ASCII...
5
by: DAHMB | last post by:
Hi all, Using Access 2007 I have a report called Sunday School Attendance based on a Query called qryAttendance the query is as follows: SELECT tblSundaySchoolAttendance.StudentID,...
5
by: Jim Mandala | last post by:
Using Access 2003 front end; SQL Server 2005 Back end: I have a complex form that has lots of data fields including about thirty or so checkboxes storing Yes/No data that I would like my users...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.