File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex constraint on a textfield

 
Jess Dancel
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, all.

I want to put a constraint on a JFormattedTextField that will only allow characters matching a regex to be entered (in this case, only hex digits 0-E).

The possible solutions I've found to this are all quite complicated. I know I've done it before and it was simple, but having trouble remembering.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33716
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jess,
Welcome to JavaRanch!

This character class matches hex: [0-9A-E]

What else are you looking for that was complicated?
 
Jessica Dancel
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering how to add that as a constraint to a textfield, so that the user can only enter those characters.
 
Hiroshi Iwatani
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use MaskFormatter. See the doc of the class for its usage.
 
Jess Dancel
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Hiroshi! MaskFormatter did exactly what I needed.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic