Solved

MutableTable Regular Expression

Posted on 2011-09-21
9
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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 …
Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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