ptreves
asked on
MutableTable Regular Expression
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
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
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.
That should work, yes.
I'm a little confused though what this has to do with Mutable Tables...
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.
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]+";
public static final String POINT_GROUP_REGEX = "[^|;&\\r\\n\\t]+";
Changing the * to + means the pattern requires at least one of the listed characters.
ASKER
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.getStri ng("GroupI DTxt"), false, SystemwideConstants.POINT_ GROUP_ID_A TTR, Integer.class, null,
false, null);
Column pointGroupName = getStringColumn(messages.g etString(" GroupNameT xt"), SystemwideConstants.POINT_ GROUP_NAME _ATTR,
new RegexEditor(SystemwideCons tants.POIN T_GROUP_RE GEX, new InvalidStringHandler(messa ges.getStr ing("Group NameTxt")) ));
Column[] columns = new Column[]{groupID, pointGroupName};
pointGroupsModel = new ColumnTableModel(columns, stemwideConstants.MAX_NUMB ER_OF_POIN T_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
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.getStri
false, null);
Column pointGroupName = getStringColumn(messages.g
new RegexEditor(SystemwideCons
Column[] columns = new Column[]{groupID, pointGroupName};
pointGroupsModel = new ColumnTableModel(columns, stemwideConstants.MAX_NUMB
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
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?
A: Perhaps...
Where, and how is the RegExp used? Are we talking about a code in your setValueAt() method?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.