2

I want to add validation for field which should check if the string contains ".html" at the end of it. See my configuration below: http://screencast.com/t/YgBIKcyU71SQ

But the validation doesn't work. It seems that my configuration of the dialog is incorrect. Could you please help me to figure out where the mistake is?

Thanks in advance

user2390742
  • 117
  • 1
  • 14

2 Answers2

1

your pattern is .html$ This is most likely incorrect. It should be the other way around: ^\.html$

HTH, Jan

Jan
  • 4,369
  • 14
  • 25
0

If you want to use info.magnolia.ui.form.validator.definition.RegexpValidatorDefinition:

  1. Before anything, you want to make sure you regex is correct

  2. Add your field validation configuration as described in the Magnolia CMS documentation.


Example of URL-friendly string validation

That's what my validation does: Only characters allowed (without the quotes): "a" to "z" (no accents/diacritics allowed & only lower case), "0" to "9", ".", "_", "-".

That's the regex pattern used: [a-z0-9._-]+

Feel free to test it on regexplanet.com/advanced/java/index.html

Add the relevant config to the dialog: Magnolia CMS: URL-friendly string validation

Find below the "validators" node config. Save this as in an xml file & import it.

<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="validators" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <sv:property sv:name="jcr:primaryType" sv:type="Name">
    <sv:value>mgnl:contentNode</sv:value>
  </sv:property>
  <sv:property sv:name="jcr:uuid" sv:type="String">
    <sv:value>112b96c1-b942-4657-9541-f8776c74d68d</sv:value>
  </sv:property>
  <sv:property sv:name="jcr:createdBy" sv:type="String">
    <sv:value>admin</sv:value>
  </sv:property>
  <sv:property sv:name="mgnl:created" sv:type="Date">
    <sv:value>2016-11-17T19:26:09.240+01:00</sv:value>
  </sv:property>
  <sv:property sv:name="mgnl:createdBy" sv:type="String">
    <sv:value>superuser</sv:value>
  </sv:property>
  <sv:property sv:name="mgnl:lastModified" sv:type="Date">
    <sv:value>2016-11-17T19:26:41.771+01:00</sv:value>
  </sv:property>
  <sv:property sv:name="mgnl:lastModifiedBy" sv:type="String">
    <sv:value>superuser</sv:value>
  </sv:property>
  <sv:node sv:name="urlCharacters">
    <sv:property sv:name="jcr:primaryType" sv:type="Name">
      <sv:value>mgnl:contentNode</sv:value>
    </sv:property>
    <sv:property sv:name="jcr:uuid" sv:type="String">
      <sv:value>4d52be80-7211-44d4-8d0a-53a50aed9bc9</sv:value>
    </sv:property>
    <sv:property sv:name="class" sv:type="String">
      <sv:value>info.magnolia.ui.form.validator.definition.RegexpValidatorDefinition</sv:value>
    </sv:property>
    <sv:property sv:name="errorMessage" sv:type="String">
      <sv:value>Only characters allowed (without the quotes): "a" to "z" (without accents), "0" to "9", ".", "_", "-". And only lower case.</sv:value>
    </sv:property>
    <sv:property sv:name="jcr:createdBy" sv:type="String">
      <sv:value>admin</sv:value>
    </sv:property>
    <sv:property sv:name="mgnl:created" sv:type="Date">
      <sv:value>2016-11-17T19:26:41.772+01:00</sv:value>
    </sv:property>
    <sv:property sv:name="mgnl:createdBy" sv:type="String">
      <sv:value>superuser</sv:value>
    </sv:property>
    <sv:property sv:name="mgnl:lastModified" sv:type="Date">
      <sv:value>2016-11-18T11:30:51.883+01:00</sv:value>
    </sv:property>
    <sv:property sv:name="mgnl:lastModifiedBy" sv:type="String">
      <sv:value>superuser</sv:value>
    </sv:property>
    <sv:property sv:name="pattern" sv:type="String">
      <sv:value>[a-z0-9._-]+</sv:value>
    </sv:property>
  </sv:node>
</sv:node>
Adriano
  • 19,463
  • 19
  • 103
  • 140