473,385 Members | 1,912 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,385 software developers and data experts.

need to break up a string

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?
Sep 29 '06 #1
5 1598
Joe Reynolds wrote:
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...

--
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.
Sep 29 '06 #2

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Joe Reynolds wrote:
>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...

--
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?
Sep 29 '06 #3
Joe Reynolds wrote:
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?

--
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.
Sep 29 '06 #4

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:uO**************@TK2MSFTNGP02.phx.gbl...
Joe Reynolds wrote:
>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?

--
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?

Sep 30 '06 #5
Joe Reynolds wrote:
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?
Obviously, yes.

Recall from my example the pattern "\S{40}". This can be interpreted as 40
consecutive non-whitespace characters. By implication, you can infer that
you can test for three spaces in a row:

/ {3}/.test(variable)

Note that for testing purposes, it is sufficient to test for "three", and
not "three or more". If you want to actually take actions (such as replace)
on the matches, then / {3,}/ is a better pattern. For more information, take
a look here:

http://msdn.microsoft.com/library/en...6f58358c0e.asp


--
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.
Oct 2 '06 #6

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

Similar topics

40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
1
by: robinsand | last post by:
I am a new C++ programmer. I am still having trouble with certain data types and constructors, among other things. I'm not sure if I've used "std::string" properly throughout this program. I need...
5
by: jhhbr549 | last post by:
I have a problem. My teacher of Java is jumping all over the book and then gave us this project. Well I got the project to run. But he wants the output in a box with an ok button on it. He gave...
1
by: Unebrion | last post by:
Alright im working on a program that prints out user imput in a frame, along with a barcode.. it is like the front of an envelope. Here is the description for the program. This...
3
by: yoyojava | last post by:
here go to this link: http://staff.beaumont.k12.tx.us/jchauvi/CS2/CS2.html ..... then click on PROJECT:Bruin Grocery ... and i am done with everything except for step 5 and 6 the search methods.. i...
4
by: svgeorge | last post by:
I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) -------------------------------------------------------------------------------- How TO COLLECT THE ROWS...
14
by: optimum | last post by:
hi i am kind of new to programming, i have managed to create a simple payroll database in C++, but now i am trying to convert in into C but i am keep getting error, can anyone help me convert this...
3
by: aashishn86 | last post by:
var weekend = ; var weekendColor = "#e0e0e0"; var fontface = "Verdana"; var fontsize = 1; var gNow = new Date(); var ggWinCal; isNav = (navigator.appName.indexOf("Netscape") != -1) ? true :...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.