need to break up a string

J

Joe Reynolds

i have an application that will take user input from a text box and write it
to an access database. i need to make sure that if they ever enter a single
line of text that it has at least 1 space for every 40 characters.

so before i write the info to the database i have to make sure there is no
lines of text that are longer than 40 characters without a space, and if
there are insert a space at the 41st character. is that as hard as it
sounds?
 
D

Dave Anderson

Joe said:
i have an application that will take user input from a text
box and write it to an access database. i need to make sure
that if they ever enter a single line of text that it has
at least 1 space for every 40 characters.

This explains your earlier problem with a CSS solution. You aren't talking
about normal blocks of text. You are talking about users who enter
contiguous blocks of characters in an attempt to break your layout. You
should have said so in the first place.


so before i write the info to the database i have to make sure
there is no lines of text that are longer than 40 characters
without a space, and if there are insert a space at the 41st
character.

I disagree. You ought to either reject it outright or display it as entered.
The data should reflect what your users enter. If you want to enforce rules,
then force your users to obey them. If you are going to let them submit
anything they want, then you have an obligation to display what you allowed
them to submit.

I am more than willing to help you approach this sanely. Here's a pure CSS
freebie:

<div style="width:250px; overflow:hidden;">

Taking a validation approach is obviously not as simple, but I can certainly
give you pointers if you like. Don't expect any more help from me if you
toppost, though.


is that as hard as it sounds?

It is exactly as easy and exactly as hard as it sounds. It sounds trivial to
me and hard to you. It *IS* trivial to me...
 
J

Joe Reynolds

Dave Anderson said:
This explains your earlier problem with a CSS solution. You aren't talking
about normal blocks of text. You are talking about users who enter
contiguous blocks of characters in an attempt to break your layout. You
should have said so in the first place.




I disagree. You ought to either reject it outright or display it as
entered. The data should reflect what your users enter. If you want to
enforce rules, then force your users to obey them. If you are going to let
them submit anything they want, then you have an obligation to display
what you allowed them to submit.

I am more than willing to help you approach this sanely. Here's a pure CSS
freebie:

<div style="width:250px; overflow:hidden;">

Taking a validation approach is obviously not as simple, but I can
certainly give you pointers if you like. Don't expect any more help from
me if you toppost, though.




It is exactly as easy and exactly as hard as it sounds. It sounds trivial
to me and hard to you. It *IS* trivial to me...



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms.

thanks. your pure css freebie only truncates the text, it doesnt force it to
wrap to the next line.
what i need to do works fine in IE but not in firefox due to a well
documented bug that has been submitted to mozilla.

although you do make a point... i would rather people not be able to pollute
my database in the first place.
and actually, your css solution isnt bad because it wouldnt hurt the display
of legitimate data.

so what would you recommend as a validator to make sure people dont try to
write nonsense to my database?
i have simple client side validators that make sure *something* is
submitted, and also server side validators that back
that up incase javascript is disabled. what i need to do is make sure no
string of text is longer than x amount of characters without a space. and if
so, yell at them.

thoughts?
 
D

Dave Anderson

Joe said:
your pure css freebie only truncates the text, it doesnt
force it to wrap to the next line.

although you do make a point... i would rather people not
be able to pollute my database in the first place.
and actually, your css solution isnt bad because it
wouldnt hurt the display of legitimate data.

Well, that's why I offered it. You can implement it immediately and with
little effort. But it does not address the core issue, which is that users
are free to enter anything they like.

On the other hand, I imagine users would stop posting long blocks of
character data once they realized it was not doing what they wanted...


so what would you recommend as a validator to make sure
people dont try to write nonsense to my database?

That's a complicated question -- or at least a question with a complicated
answer. I can't speak for other "nonsense", but for this specific issue, I
would use a regular expression, such as:

JScript:
if (/\S{40}/.test(variable)) ... // Yell at user

VBScript (untested conversion of the JScript example):
Set rx = New RegExp
rx.pattern = "\S{40}"
If rx.Test(variable) Then ... ' Yell at user

Does that help?
 
J

Joe Reynolds

Dave Anderson said:
Well, that's why I offered it. You can implement it immediately and with
little effort. But it does not address the core issue, which is that users
are free to enter anything they like.

On the other hand, I imagine users would stop posting long blocks of
character data once they realized it was not doing what they wanted...




That's a complicated question -- or at least a question with a complicated
answer. I can't speak for other "nonsense", but for this specific issue, I
would use a regular expression, such as:

JScript:
if (/\S{40}/.test(variable)) ... // Yell at user

VBScript (untested conversion of the JScript example):
Set rx = New RegExp
rx.pattern = "\S{40}"
If rx.Test(variable) Then ... ' Yell at user

Does that help?



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms.


thank you. ive written a pretty good vbs validator and the only thing i need
to check for (assuming all the other tests pass) is 3 or more spaces in a
row.
is that a simple thing to do with a regexp?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top