473,396 Members | 2,111 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,396 software developers and data experts.

Special Characters Processing

How do I detect the special characters " ' or & when the user pushed
them.

I have this code:
<input type='text' onKeyUp='ck_char(this,event);'>

function ck_char(fld, e)
{
var key = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
key = String.fromCharCode(whichCode); // Get key value from key code
alert(key);
}

Since each one of these special keys also involve pressing the shift
key, the only value I get passed back is the last key pressed, which in
the case of & would always be 7.

What I'd like to do is detect these special characters when they are
entered and go ahead and replace them with an appropriate equivalent.

Mike
Jul 20 '05 #1
3 1650
Michael Hill wrote on 05 mrt 2004 in comp.lang.javascript:
How do I detect the special characters " ' or & when the user pushed
them.

I have this code:
<input type='text' onKeyUp='ck_char(this,event);'>

function ck_char(fld, e)
{
var key = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
key = String.fromCharCode(whichCode); // Get key value from key
alert(key);
}
where do you use the "fld" for ?

========================

alert(/'"/.test(key))

will give "true" if either ' or " is found.
Since each one of these special keys also involve pressing the shift
key, the only value I get passed back is the last key pressed, which
in the case of & would always be 7.

What I'd like to do is detect these special characters when they are
entered and go ahead and replace them with an appropriate equivalent.


wouldn't we all?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2

where do you use the "fld" for ?
Another part of the script that I didn't show.

========================

alert(/'"/.test(key))

will give "true" if either ' or " is found.


This is giving me "false" for everything I push.

Mike
Jul 20 '05 #3
Michael Hill wrote on 05 mrt 2004 in comp.lang.javascript:
alert(/'"/.test(key))

will give "true" if either ' or " is found.


This is giving me "false" for everything I push.


Ah yes, the key is a number,
so you will have to convert to a character
and I forgot the []

<script>
key=39 // '
key= String.fromCharCode(key)
alert(/['"]/.test(key))

key=34 // "
key= String.fromCharCode(key)
alert(/['"]/.test(key))
</script>

tested IE6

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Roy W. Andersen | last post by:
I've been searching google about this for days but can't find anything, so I'm hoping someone here can help me out. I'm trying to create zip-files without needing the zip-file extension in PHP,...
3
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
25
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found...
1
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file,...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
2
by: withers | last post by:
XML gives an error when I have a £ sign (GBP) - £ - in a string. I've fixed this by converting it to its HTML number. In case other characters may cause the same error, I'm converting characters...
0
by: AAaron123 | last post by:
Been playing with asp:changepassword and have it looking OK except that I can't elininate or change the title at the top that says "Change Your Password". It's a repeat of my pages title. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.