Skip to main content

RegexFormatter - pattern for relative path

No replies
Joined: 2008-02-22


I've got a JFormattedTextField and I want to allow a user to enter a relative path - i.e. no leading "/".

I created a pattern:

String s = "^[A-Za-z0-9][-/_A-Za-z0-9]*";

And this seemed to work fine - I try to enter a "/" as the first character and it beeps at me, but as the 2nd or later character, it is allowed. So great.
Unfortunately, if I enter "rupert/woodman" and then backspace, it won't let me delete the initial "r" (it doesn't matter what the first character is - it won't let me delete it).

Is this a bug, or is my pattern not correct?

Many thanks