File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Regex constraint on a textfield Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regex constraint on a textfield" Watch "Regex constraint on a textfield" New topic
Author

Regex constraint on a textfield

Jess Dancel
Greenhorn

Joined: Nov 07, 2007
Posts: 11
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

Jess,
Welcome to JavaRanch!

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

What else are you looking for that was complicated?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jessica Dancel
Greenhorn

Joined: Dec 07, 2006
Posts: 10
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

Joined: Jan 15, 2008
Posts: 3
Use MaskFormatter. See the doc of the class for its usage.
Jess Dancel
Greenhorn

Joined: Nov 07, 2007
Posts: 11
Thank you, Hiroshi! MaskFormatter did exactly what I needed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex constraint on a textfield
 
Similar Threads
http-method
Filter only GET Methods
Amout validation
HfSJ 637 page Errata
security constraint : http-method