cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expression Issue in constraints Tag when using custom model

ajay_k
Champ on-the-rise
Champ on-the-rise

Hello,

                     I created custom model to apply for uploaded documents in alfresco share. My customModel.xml has constraints as

below:

<?xml version="1.0" encoding="UTF-8"?>

<model name="t:membershipdocumentsmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

<!-- Optional meta-data about the model -->
<description>Membership Document Model</description>
<author>Techsophy</author>
<version>1.0</version>

<!-- Imports are required to allow references to definitions in other models -->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
<import uri="http://www.alfresco.org/model/system/1.0" prefix="sys"/> 
</imports>

<namespaces>
<namespace uri="http://www.tech.com/model/content/1.0" prefix="t" />
</namespaces>

 

<constraints>
<constraint name="t:alphanumeric" type="REGEX">
<parameter name="expression">
<value>[a-zA-Z0-9]</value>
</parameter>
<parameter name='requiresMatch'><value>true</value></parameter>
</constraint>
<constraint name="t:length" type="LENGTH">
<parameter name='minLength'><value>1</value></parameter>
<parameter name='maxLength'><value>10</value></parameter>
</constraint>
</constraints>

 

<types>
<!-- Enterprise-wide generic document type -->
<type name="t:membership_doc">
<title>Transaction Document</title>
<parent>cm:content</parent>
<properties>
<property name="t:membership_id">
<type>d:text</type>
<mandatory>true</mandatory>
<constraints>
<constraint ref="t:alphanumeric" />
<constraint ref="t:length" />
</constraints>
</property>
</properties>
</type>
</types>

 

</model>

My goal is to allow only alphanumeric characters but for above regular expression it is showing failure message

And it is allowing the special characters which i won't need.

Is there any mistake in my approach?

Thanks & Regards

Ajay

1 ACCEPTED ANSWER

jpotts
World-Class Innovator
World-Class Innovator

I tested your regex on a constraint in one of my models and saw the same problem you were seeing.

Try changing your regex to:

[a-zA-Z0-9]*

I tested that and it works.

View answer in original post

4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator

I am confused because your error message is complaining about a property named membership_id which I do not see in the model you are sharing.

ajay_k
Champ on-the-rise
Champ on-the-rise

Hello Jeff Potts

 

Sorry for that, by mistake i posted different model.Below is the model i'm using

 

<?xml version="1.0" encoding="UTF-8"?>

<model name="t:membershipdocumentsmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

<!-- Optional meta-data about the model -->
<description>Membership Document Model</description>
<author>Techsophy</author>
<version>1.0</version>

<!-- Imports are required to allow references to definitions in other models -->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
<import uri="http://www.alfresco.org/model/system/1.0" prefix="sys"/> 
</imports>

<namespaces>
<namespace uri="http://www.tech.com/model/content/1.0" prefix="t" />
</namespaces>

<constraints>
<constraint name="t:alphanumeric" type="REGEX">
<parameter name="expression">
<value>[a-zA-Z0-9]</value>
</parameter>
<parameter name='requiresMatch'><value>true</value></parameter>
</constraint>
<constraint name="t:length" type="LENGTH">
<parameter name='minLength'><value>1</value></parameter>
<parameter name='maxLength'><value>10</value></parameter>
</constraint>
</constraints>

<types>
<!-- Enterprise-wide generic document type -->
<type name="t:membership_doc">
<title>Transaction Document</title>
<parent>cm:content</parent>
<properties>
<property name="t:membership_id">
<type>d:text</type>
<mandatory>true</mandatory>
<constraints>
<constraint ref="t:alphanumeric" />
<constraint ref="t:length" />
</constraints>
</property>
</properties>
</type>
</types>

</model>

jpotts
World-Class Innovator
World-Class Innovator

I tested your regex on a constraint in one of my models and saw the same problem you were seeing.

Try changing your regex to:

[a-zA-Z0-9]*

I tested that and it works.

ajay_k
Champ on-the-rise
Champ on-the-rise

Thanks Jeff Potts, its working now.