how should I validate fields?

I have a GUI app I am developing with several forms. Fields on forms are Name, street, city, zip, etc....

I pass in a little grammar rule for each field that makes sure it is alpha, numeric or alpha numeric. That's all the checking I do currently.

How can I make sure a textfield does not allow them to type in more than 15 characters if that is what I want limit to be for say FirstName field?

If they try to type the 16th character I want them to get the annoying beep and not process a key pressed event.

Any ideas? classes I should look at ? listeners?

Also simple code would be greatly appreciated if anyone has time.

thanks ahead of time..

jmschrei

[711 byte] By [jmschrei] at [2007-9-26 4:07:22]
# 1
use maxsize="15" in text tag.for example,<input type="text" name="Name" maxsize="15" >that text tag allows upto 15 characters only. it won't allow the 16th character.
srinivaspeyyala at 2007-6-29 13:08:31 > top of Java-index,Archived Forums,Java Programming...
# 2
try a JTextField with a document added to it.You can then add a document listener, which will then allow you to process any change that happens..... including the length!
apcampbell at 2007-6-29 13:08:31 > top of Java-index,Archived Forums,Java Programming...
# 3
I am creating an application using AWT.
jmschrei at 2007-6-29 13:08:31 > top of Java-index,Archived Forums,Java Programming...
# 4
I should have been more specific. Can I use some sort of document listener on TextField.
jmschrei at 2007-6-29 13:08:31 > top of Java-index,Archived Forums,Java Programming...
# 5

> I should have been more specific. Can I use some sort

> of document listener on TextField.

you can not set a document into TextField (but u can for JTextField).

Suggest you look at addkeylistener, although there are other listeners listed in the documentation see http://java.sun.com/j2se/1.3/docs/api/java/awt/TextField.html

apcampbell at 2007-6-29 13:08:31 > top of Java-index,Archived Forums,Java Programming...