cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with REGEX constrain in Alfresco Share

mitpatoliya
Star Collaborator
Star Collaborator

I having REGEX constrain on one of the property with datatype as integer.

There is one issue seems like bug.

If value is being successfully validated from user interface on server side it fails and If I add non-matching value it gives error on client side it self so this looks like some bug.

Error which I got when I add proper value.


    <constraint name="test:fractionConstrain" type="REGEX">
        <parameter name="expression"><value>.*[^0-9].*</value></parameter>
        <parameter name="requiresMatch"><value>false</value></parameter>
     </constraint>


org.alfresco.repo.node.integrity.IntegrityException: 04270037 Found 1 integrity violations:
Invalid property value:
   Node: workspace://SpacesStore/e9ddba34-64bc-4626-b4f0-2d599d71de56
   Type: {com.asm.recipe.model}nutritions
   Property: {com.asm.recipe.model}servingSize
   Constraint: 04270036 Value '5' matches regular expression: .*[^0-9].*
   at org.alfresco.repo.node.integrity.IntegrityChecker.checkIntegrity(IntegrityChecker.java:661)
11 REPLIES 11

ipirat
Champ in-the-making
Champ in-the-making
in your original post, some XML tags seem to went awry. I assume, your config is like this:

     &lt;constraint name="test:regex1" type="REGEX"&gt;
        &lt;parameter name="expression"&gt;&lt;value&gt;.*[0-9].*&lt;/value&gt;&lt;/parameter&gt;
        &lt;parameter name="requiresMatch"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/parameter&gt;
     &lt;/constraint&gt;

this will reject any value containing at least one digit 0-9. (so, basically it will reject every integer)


PS: what is your intention / business case?

Thank you for adding the code. You I have similar piece of code only diff is "requiresMatch" value is true.
I want user to allow only 0 and whole number only.

ipirat
Champ in-the-making
Champ in-the-making
In that case, i would suggest the MINMAX constraint with value 0.

If it has to be REGEX, use ^[0-9]+$

kaynezhang
World-Class Innovator
World-Class Innovator
if you want to use REGEX ,please try
^(0|[1-9][0-9]*)$

iPirat's will match any digital character sequence begins with 0 (for example 02343) besides  0 and number

ipirat
Champ in-the-making
Champ in-the-making
you are absolutely right. (which shouldnt make any difference, as the type is d:int)

I'd still suggest to use MINMAX with min value 0 for the given business case.

mitpatoliya
Star Collaborator
Star Collaborator
Thank you both of you for your response. Actually I think I have not given clear explanation.
It looks like issue is not with REGEX.
For Instance if I am using regular expression given by ipirate It does give error on UI when I feed in any negative value in text box.
But once I give proper value and submit it does not allow to update it showing "could not update details."
Also in logs error comes up which I had posted in original post.

So, In short looks like Client side validation and server side validation both are conflicting.

ipirat
Champ in-the-making
Champ in-the-making
just tried this:

                <property name="my:regexTest">
                    <type>d:int</type>
                    <multiple>false</multiple>
                    <constraints>
                        <constraint name="my:regex1" type="REGEX">
                            <parameter name="expression">
                                <value>^[0-9]+$</value>
                            </parameter>
                            <parameter name="requiresMatch">
                                <value>true</value>
                            </parameter>
                        </constraint>
                    </constraints>
                </property>


works like a charm.
<ul>
<li>if I use anything other than a digit, the UI tells me "illegal characters"
<li>if I use only digits, the property value is saved perfectly.
<li>Any leading zeroes are deleted when the value is saved
<li>if I use too many digits, I get a java.lang.NumberFormatException
</ul>

(used Alfresco Version: 4.2.e)

Again, I'd advise to use

                <property name="my:regexTest">
                    <type>d:int</type>
                    <multiple>false</multiple>
                    <constraints>
                        <constraint name="my:minMax1" type="MINMAX">
                            <parameter name="minValue">
                                <value>0</value>
                            </parameter>
                        </constraint>
                    </constraints>
                </property>

kaynezhang
World-Class Innovator
World-Class Innovator
In server side ,regex constraint is evaluated  using java.util.regex.
In client side ,regex is evaluated using JavaScript RegExp object.
It might be possible that java and javascript have different explanation on same regular expression.

You can try mime

^(0|[1-9][0-9]*)$

mitpatoliya
Star Collaborator
Star Collaborator
Hi kaynezhang, Unfortunately Same issue with your expression as well.