Forums Register Login

Entry limit to Textfields

+Pie Number of slices to send: Send
hi all, i wrote some code to check the length of textfields. as i have to save all into a DB, where i've got some varchar(10). the code i have allows you to type only 10 chars into the respective textfield, but my problem is, that if i paste a longer string into it (from clipboard), the textfields accepts it and while i try to save, i get a DB exception that a submitted value is too big. am thankfull for any help.
aa.
+Pie Number of slices to send: Send
yes it's happened when u paste at textfeild .......
if u dont need the word longer then 10 chars
my logic is
u have to put this code at the event of button

// tf is the veriable of textfeild
String str = tf.getText();
int i = str.lenght();
if (i<10)
{
System.out.println("ok");
}
esle{
System.out.println("again");
// you have to write under 10
//
}
+Pie Number of slices to send: Send
Hi Linda,
There is an excellent (in my opinion) example of how to achieve this in "The Java Tutorial" (assuming you haven't already looked at it):
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html#validation
Hope this helps you.
Good Luck,
Avi.
+Pie Number of slices to send: Send
thank you very much. although the java tutorial implementation would be much better as i did now, i chose the way of getting the stringbuffer length and check it before writing to the DB. it's not too proper, but it works for the moment! thx again.
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1148 times.
Similar Threads
multiple db statements in a jsp page
Blank Frame or Panel
JPanel to JPanel in a JFrame
Newbie needs help
Dynamic textfield creation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:02:18.