Solved

MutableTable Regular Expression

Posted on 2011-09-21
9
201 Views
Last Modified: 2012-05-12
Hello,

I have a global constant that allows the validation of fields from a MutableTable.

    public static final String POINT_GROUP_REGEX = "[^\\r\\n\\t]*";

    public static final String POINT_GROUP_REGEX = "[^|;&\\r\\n\\t]*";

to take into account the special characters. |&;
Is that all that is required to fix this bug ?

Paolo
0
Comment
Question by:ptreves
  • 5
  • 3
9 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577299
Yes. If you wanted to match a | character without listing other possible characters in [] brackets, you'd need to escape it like \\| but it's ok while it's contained in [] brackets.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36577300
That should work, yes.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36577302
I'm a little confused though what this has to do with Mutable Tables...
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577304
Note also that your pattern is matching ^ as a character, not as a start-of-string placeholder; I'm not sure whether that's what you intended.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577313
And actually, I wonder if the expression is a bit meaningless in the first place. The * after the characters in [] allows zero characters to be matched, which probably isn't what you want. Maybe you want:
    public static final String POINT_GROUP_REGEX = "[^|;&\\r\\n\\t]+";
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577317
Changing the * to + means the pattern requires at least one of the listed characters.
0
 

Author Comment

by:ptreves
ID: 36580574
Changing the quantifier from * to +, as follows:

    public static final String POINT_GROUP_REGEX = "[^|;&\\r\\n\\t]+";

What I realy want is to prevent users from entering any of the three special characters  |;& in a mutable table used for "Group Names". As soon as a user enters any of those three special characters or any of the control characters, he should be prompted to change/correct his entry.

Here is the java routine that processes the Regular Expression:

        ColumnTableModel pointGroupsModel;
        Column groupID = getColumn(messages.getString("GroupIDTxt"), false, SystemwideConstants.POINT_GROUP_ID_ATTR, Integer.class, null,
                false, null);

        Column pointGroupName = getStringColumn(messages.getString("GroupNameTxt"), SystemwideConstants.POINT_GROUP_NAME_ATTR,
                new RegexEditor(SystemwideConstants.POINT_GROUP_REGEX, new InvalidStringHandler(messages.getString("GroupNameTxt"))));

        Column[] columns = new Column[]{groupID, pointGroupName};
        pointGroupsModel = new ColumnTableModel(columns, stemwideConstants.MAX_NUMBER_OF_POINT_GROUPS);

The problem is that after compiling and testing the code, the user can still enter those special characters.
Is the regular expression at fault ?

Paolo
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36580777
Q: Is the regular expression at fault ?
A: Perhaps...

   Where, and how is the RegExp used?  Are we talking about a code in your setValueAt() method?
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 36583894
The pattern:
"[^|;&\\r\\n\\t]+"
will match when it detects one or more of the characters specified, in which case you want the validation code to prompt the user for a correction. Note that if just one character in the specified list makes the value invalid, then the + is redundant (as the "or more" part of the "one or more" meaning of it is unnecessary; therefore this pattern would do the trick:
"[^|;&\\r\\n\\t]"
but you need to get the surrounding logic of your code right too!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For some reason Google Apps has decided to reserve 'www' for your new domain which results in an error when trying to map the web address 'www' to a certain site in your Google Sites. The error is 'this address is already being used' and after some …
These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question