Solved

MutableTable Regular Expression

Posted on 2011-09-21
9
209 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
2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

 
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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

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 …
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

636 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