PDA

View Full Version : text field in DB, length limitation


ShMiL
03-31-2003, 02:41 PM
I have a text field in the DB that it's maximum length is 150 chars.
Now I have a form with <textarea> in which I allow to input ONLY 150 chars (using JS script).
The problem is that I have an habbit to always use a function (vb) which encodes the data before I add it to the DB - it replaces many problematic chars (like: <,>,",',& and some more) with it's HTML-ic replacement (like: &# 34;,&# 39;,& lt; etc).

I guess you understand the probblem...
When the user inputs the char: < the JS sees it as one char, but after I encode it for the DB it becomes: &lt; which is three chars!

Anyone have any idea?
If I could change the JS script to recognize "my" problematic chars and to count them recording to it's replacements.


Thanks

Mhtml
03-31-2003, 02:57 PM
Why not just change the field type to memo? You can still limit the chars to 150 in the js and before you htmlencode run a check in asp to make sure.

ShMiL
03-31-2003, 03:13 PM
that's an option - but I'd really like to make it as efficient as possible, and it's not necessary to save 150 chars in a memo field.

Any idea how to make it work with the 150 chars text field?

Mhtml
03-31-2003, 03:18 PM
You could just filter out ' ..And htmlencode the rest when you pull it out of the db! That should save space.

raf
03-31-2003, 04:49 PM
I totally agree with Mhtml.

When you save it to the db, you only need to replace the single quotes (read the sticky on top of this forum). These single quotes will magically be saved as ... single quotes, so the string will be exactly the lenght as the posted value.

When you display then, you can then encode it to html (for instance, in ASP with
server.HTMLEncode()