Skip to main content

Validation JTextField

2 replies [Last post]
Joined: 2003-08-18


Does anybody knows which the best pratice for validate the input information in a JTextField???

Is there a component free for this validation???


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-02-17

Have a look at JFormattedTextField, it can validate input data

Also check the following article

it shows how to create RegexFormatter which allows using regular expressions for validation

If you dont want to use JFormattedTextField you can subclass PlainDocument class which would validate data using regexp or whatever and set it to your textfields

see JTextField in javadoc for example
and JTextField.setDocument(Document doc)

good luck

Scott Violet

In addition to JFormattedTextField and a custom PlainDocument you could
also create a custom DocumentFilter. While DocumentFilter was primarily
designed for JFTF it can be used on it's one. Creating a custom
DocumentFilter is a bit lighter weight than creating a custom Document.